调用摄像头拍的照片,由于系统对应用拍摄的照片有限制,所以一般不需要进行裁剪。但是直接从相册获取照片时,可能会由于手机相册中的图片太大造成显示不了,所以需要进行剪裁。具体代码如下:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.zpreston.homework7_16.MainActivity">
<ImageView
android:id="@+id/header"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginTop="80dp"
android:src="@drawable/header"/>
<RelativeLayout
android:id="@+id/relative"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal">
<ImageView