1

I'm now facing a problem that my galaxy nexus keep looping on "loading image" when go into crop function.Below is my coding:

Intent openCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 
startActivityForResult(openCamera, click_camera);

protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent){
            if (imageReturnedIntent != null)
                {if(requestCode == click_camera && resultCode == RESULT_OK) { 
                    picUri = imageReturnedIntent.getData();
                    Crop();             
                }

            else {
                **my coding part**
}

/* crop method */
private void Crop(){    
    try {

        //call the crop action from intent (default from device)
        Intent cropIntent = new Intent("com.android.camera.action.CROP"); 
        //indicate image type and Uri
        cropIntent.setDataAndType(picUri, "image/*");
        //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", 300);
        cropIntent.putExtra("outputY", 300);
        cropIntent.putExtra("scale", true);
        cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
        cropIntent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
        //retrieve data on return
        cropIntent.putExtra("return-data", true);
        //start the activity - we handle returning in onActivityResult
        startActivityForResult(cropIntent, PIC_CROP);  
    }
    //respond to users whose devices do not support the crop action
    catch(ActivityNotFoundException anfe){
        //display an error message
        String errorMessage = "Whoops - your device doesn't support the crop action!";
        Toast toast = Toast.makeText(this, errorMessage, Toast.LENGTH_SHORT);
        toast.show();
    }
}

Is it my crop function wrong ? can anyone help what is going wrong?

  • Please provide a logcat? – shkschneider Nov 26 '12 at 17:18
  • Bear in mind that some devices do not support `com.android.camera.action.CROP`. That is not part of the Android SDK and does not have to exist on any given device. You really should be using an existing image cropping library or writing your own image cropping code. – CommonsWare Nov 26 '12 at 21:00

1 Answers1

2

This is how I solved the problem for my own situation.

Take this:

cropIntent.putExtra("outputX", 300);
cropIntent.putExtra("outputY", 300);

And change in :

cropIntent.putExtra("outputX", 256);
cropIntent.putExtra("outputY", 256);

Reason: click here

EDIT

I've found a solution

set

cropIntent.putExtra("outputX", ANY VALUE);
cropIntent.putExtra("outputY", ANY VALUE);
cropIntent.putExtra("return-data", false);
cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, mImageCaptureUri);

to see cropped image

BitmapFactory.decodeFile(mImageCaptureUri.getPath());

Enjoy :)

Community
  • 1
  • 1
Alessandro.Vegna
  • 1,262
  • 10
  • 19