Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
// 设置裁剪
intent.putExtra("crop", "true");
// aspectX aspectY 是宽高的比例
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
// outputX outputY 是裁剪图片宽高
intent.putExtra("outputX", 80);
intent.putExtra("outputY", 80);
intent.putExtra("return-data", true);
startActivityForResult(intent, RESULT_REQUEST_CODE);
在onActivityResult()方法中获取裁剪后的图片数据:
/**
* 保存裁剪之后的图片数据
*
* @param picdata
*/
private void getImageToView(Intent data) {
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photo = extras.getParcelable("data");
BufferedOutputStream bos;
try {
bos = new BufferedOutputStream(new FileOutputStream(headFile));
photo.compress(Bitmap.CompressFormat.JPEG, 80, bos);
bos.flush();
bos.close();
userImage.setImageBitmap(ImageTools.toRoundCorner(photo, 8, 0));
mPersonalInfoActivtyControl.setVcardHimg(headFile.getAbsolutePath());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}