pkramaric
pkramaric

Reputation: 165

android.os.TransactionTooLargeException with Crop Activity

I have an application where a user can upload an image for their user profile. In my application I allow the user to crop an image using the native cropper. However when I try to crop a large image I get the following error in my Logcat:

!!! FAILED BINDER TRANSACTION !!!
Exception when starting activity com.example.somename/com.example.somename.Profile
android.os.TransactionTooLargeException

I start the cropper using the following bit of code:

Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
cropIntent.setDataAndType(imageFileUri , "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("aspectX", 1);
cropIntent.putExtra("aspectY", 1);
cropIntent.putExtra("outputX", 265);
cropIntent.putExtra("outputY", 265);
cropIntent.putExtra("scale", true);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);

then in my onActivityResult the following code gets the cropped image:

Bundle extras = data.getExtras();
Bitmap selectedBitmap = extras.getParcelable("data");
imgDisplayPic.setImageBitmap(selectedBitmap);

I am assuming the issue is with the cropper trying to send a large bitmap as a parcelable back to my activity. Is there any way around this? Or an alternative way to get a cropped image?

Thanks in advance for any help.

Upvotes: 3

Views: 3297

Answers (1)

pkramaric
pkramaric

Reputation: 165

In case anyone else comes across this problem I have managed to solve it with help from the following link: http://www.androidworks.com/crop_large_photos_with_android. I solved the problem by implementing Option #2 found in the link.

As I had suspected originally the problem was send a large bitmap back from the cropper as a parcelable. Instead what I did (as the link suggests) is save the contents of the cropper into a temporary file and then read that content in my main activity/fragment. In order to not send the content back via parcelable the main change I had to do to my code above is

cropIntent.putExtra("return-data", false);

and added

cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempURI);

where "tempURI" is the Uri of the temp file where the contents of the cropper will be saved. Then in the onActivityResult you need to remove the following line

Bitmap selectedBitmap = extras.getParcelable("data");

Instead you will need some code to read the contents from your temporary file.

Hopes this helps anyone who comes across this problem.

EDIT: Link is dead, try Internet Archive one instead.

Upvotes: 5

Related Questions