使用活动结果裁剪图像时出现问题。我已在设备 >6 上设置权限。但是当显示裁剪和裁剪成功时,结果数据为空。(imageReturnedIntent.getData()
我们为空,意图数据也为空)。这是代码裁剪图像。
public static Intent cropIntent(Uri inUri, int outputX, int outputY,
boolean isScale) {
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(inUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", outputX > 0 ? outputX : 100);
cropIntent.putExtra("aspectY", outputY > 0 ? outputY : 100);
cropIntent.putExtra("outputX", outputX > 0 ? outputX : 100);
cropIntent.putExtra("outputY", outputY > 0 ? outputY : 100);
cropIntent.putExtra("scale", isScale);
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "img.jpg");
Uri mCropImagedUri = Uri.fromFile(file);
cropIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mCropImagedUri);
cropIntent.putExtra("return-data", true);
return cropIntent;
}
这是代码活动结果
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) {
super.onActivityResult(requestCode, resultCode, imageReturnedIntent);
if (callbackManager != null) {
callbackManager.onActivityResult(requestCode, resultCode, imageReturnedIntent);
}
switch (requestCode) {
case SELECT_PHOTO:
if (resultCode == RESULT_OK) {
Uri uriImage = imageReturnedIntent.getData();
System.out.println(">>>> uri "+uriImage);
// CommonUtils.cropImage(uriImage,HomeActivity.this,SELECT_CROP_IMAGE);
startActivityForResult(CommonUtils.cropIntent(uriImage,
200, 200, true), SELECT_CROP_IMAGE);
}
break;
case SELECT_CROP_IMAGE:
if (resultCode == RESULT_OK) {
// Uri uri = imageReturnedIntent.getData();
System.out.println(">>>>> "+imageReturnedIntent.getData());
Bundle extras = imageReturnedIntent.getExtras();
if (extras == null) {
System.out.println(">>>>> check intent");
return;
}
// Bitmap bitMapScale = extras.getParcelable("data");
Uri uri = extras.getParcelable(MediaStore.EXTRA_OUTPUT);
try {
Bitmap bitMapScale = MediaStore.Images.Media.getBitmap(this.getContentResolver(), uri);
System.out.println(">>>>>> check " + bitMapScale);
// yourSelectedImage.recycle();
// base64
String myBase64Image = CommonUtils.encodeToBase64(bitMapScale, Bitmap.CompressFormat.PNG, 100);
// bitMapScale.recycle();
assert uri != null;
LocalStorage.getShareInstance().saveUriAvatar(uri.toString());
LocalStorage.getShareInstance().saveBase64Image(myBase64Image);
UserModel userModel = LocalStorage.getShareInstance().getUserLogin();
if (userModel == null) {
// if user have not login.
if (uiLeftMenu != null) {
uiLeftMenu.fillImage(uri);
}
} else {
System.out.println(">>>>>> check data");
if (CommonUtils.isStringDataValid(myBase64Image)) {
upLoadImageToServerWithStringBase64(myBase64Image);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
break;
}
}
问题是什么?