通过相机拍摄照片后裁剪照片时,棉花糖设备出现问题。它在以下 6 版本设备上工作正常。这是我的代码:
if (requestCode == CAMERA_PICTURE) {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
// set data type to be sent , indicate image type and Uri of image
cropIntent.setDataAndType(mCapturedImageURI, "image/*");
List<ResolveInfo> list = getPackageManager().queryIntentActivities( cropIntent, 0 );
int size = list.size();
// handle the case if there's no cropper in the phone
if (size == 0) {
Toast.makeText(this, "Can not find image crop app", Toast.LENGTH_SHORT).show();
return;
} else {
//set crop properties
cropIntent.putExtra("crop", "true");
//indicate aspect of desired crop
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
//indicate output X and Y
cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);
String fileName = Ut.getDateTimeStamp();
ContentValues values = new ContentValues();
values.put(MediaStore.Images.Media.TITLE, fileName);
mCropImageURI = getContentResolver()
.insert(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
values);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT,
mCropImageURI);
//retrieve data on return
cropIntent.putExtra("return-data", true);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, CROP_PICTURE);
return;
}
} else if (requestCode == CROP_PICTURE) {
getCameraPhotoFromIntent(data);
setImagePathToSource();
}
我已经通过删除自己修复了
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT,
mCropImageURI);
因为 nexus 9 使用照片而不是图库和"照片"应用程序不允许媒体 URI .因此,通过删除它,我能够裁剪图像。
谢谢。
试试这个:
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.MARSHMALLOW) {
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCropImageURI);
}