protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode){
case TAKE_PHOTO :
if(resultCode == -1){ // 拍照保存成功返回
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(uri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", outputX);
intent.putExtra("outputY", outputY);
intent.putExtra("scale", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
intent.putExtra("return-data", true);
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
intent.putExtra("noFaceDetection", true); // no face detection
startActivityForResult(intent,CROP_PICTURE);
}
break;
case CROP_PICTURE:
if (data == null) {
//大部分手机在剪切取消时返回是null,但是三星的目前测试发现data有值。
return;
}
if(imageFileUri != null){
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap bitmap = extras.getParcelable("data");
if(bitmap!=null){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 75, stream);// (0 - 100)
mHandler.obtainMessage(UPDATE_IMG, bitmap).sendToTarget();
imageView.setImageBitmap(bitmap);
}
}
}
break;
}
最近在调试拍照剪切头像发现一个问题 三星手机在剪切点击取消后,data不为null 只能根据bitmap是否为null去判断.