I'm trying to crop an image from the media gallery. I'm able to access the image, start the default crop tool and even save the cropped image result.
However, the intent I'm using just will not return any results if the cropping was successful.
My MAIN Method:
// Crop photo intent.
Intent intent = new Intent("com.android.camera.action.CROP", null);
intent.setData(uri);
intent.putExtra("outputX", outputX);
intent.putExtra("outputY", outputY);
intent.putExtra("aspectX", aspectX);
intent.putExtra("aspectY", aspectY);
intent.putExtra("scale", scale);
intent.putExtra("return-data", true);
intent.putExtra(MediaStore.EXTRA_OUTPUT, createTempCroppedImageFile());
intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
// Publish intent to crop picture.
activity.startActivityForResult(intent, activity.CROP_PHOTO_REQUEST_CODE);
– OnActivityResult() Method –
// Photo crop activity.
if (requestCode == CROP_PHOTO_REQUEST_CODE) {
if (resultCode == RESULT_OK) {
Log.d(TAG, "user cropped a photo");
signupScreen.setImage(new PhotoTool(this).getTempCroppedImageFileLocation());
} else
Log.d(TAG, "user cancelled photo crop");
}
If I cancel out of the crop activity, I get the "user cancelled photo crop" message successfully. But if I crop an image, the new cropped image will appear in the target directory but the OnActivityResult() function never ever gets called. What gives?
Looking at the LogCat, I'm finding that every time I save the cropped image, "JavaBinder" complains "Failed Binder Transaction". I understand this is somehow related to memory, but the cropped file is only 24KB in size.
Found the problem to this issue. It's unfortunately an Android limitation.
See Android cropper cannot go beyond 256?
I had set the output of my cropped image to 400x400. Unfortunately Android's default cropper can only do 256x256. This is so utterly frustrating, especially when there's no documentation on limits.