3

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.

double-beep
  • 5,031
  • 17
  • 33
  • 41
colinwong
  • 382
  • 3
  • 12
  • duplicate check this answer: http://stackoverflow.com/questions/12758425/how-to-set-the-output-image-use-com-android-camera-action-crop/ – hcpl Apr 17 '13 at 09:12

2 Answers2

15

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.

Community
  • 1
  • 1
colinwong
  • 382
  • 3
  • 12
  • Yes this is correct, it seems you have to set the outputX and outputY to 256 or lower, but...you can adjust the crop size in the croppping intent and it will return the actual size the user cropped to. So this is a bug, but the cropping tool still works :) – Danuofr Feb 03 '13 at 21:00
1

Are you calling setResult(int) (link) in the crop intent?

UPDATE:\

Sending RESULT_CANCELLED is the default. It will always be sent back unless you implement a few things.

In your crop intent, when you have the finished the editing (i.e. the user taps the done button, or something similar), part of that process would call setResult(RESULT_OK).

example:

public void doneBTNPressed( View view ) {
    if ( view.getId() == R.id.doneBTN ) {
        this.isCropped = true;
    }
}

@Override    
protected void onPause() {
        if ( this.isCropped ) {
            setResult(RESUL_OK);
        }
        super.onPause();
    }

That result (RESULT_OK, plus another integer you specify) gets passed back to the calling Activity (assuming startActivityForResult() was used). There also a few overrides, depending on your needs. In the calling (parent) activity, you would have to implelement onActivityResultint,int,Intent) to get the result from the exiting activity.

In the link provided above, there is a section titled "Starting Activities and Getting Results," which explains the multiple ways to get information out of an exiting actvity.

Mike D
  • 4,938
  • 6
  • 43
  • 99
  • I'm not following. Where do I do "setResult(int)" in the intent? – colinwong Feb 19 '12 at 02:03
  • Mike. I'm sorry for confusion. I do understand the "setResult()" from an activity to child activity standpoint. The cropping tool I'm using is Android's default cropping tool. I'm using Galaxy Nexus on Android 4.0. So its not something I can control. – colinwong Feb 19 '12 at 03:09
  • @colinwong After looking at your update, I don't think I can answer your qeustion. I have yet to start developing for Android 4.0, so I have no experience there. Sorry. – Mike D Feb 19 '12 at 04:36