I have created a sample app for cropping images and I am calling the built-in crop
intent.
Here is my code:
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
intent.setData(mImageCaptureUri);
intent.putExtra("outputX", 200);
intent.putExtra("outputY", 200);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("return-data", true);
How can I modify the crop area as per the user's input?
Yes you can, you need to change outputX
/outputY
and aspectX
/aspectY
according to your need. See also
- Select and crop with a maximum size in android
- Android Camera Intent with Crop
- How to crop the parsed image in android?
Just remove the output/aspect/scale parameters.
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setType("image/*");
intent.setData(mImageCaptureUri);
intent.putExtra("return-data", true);
If this doesn't give you the result you want, try adding some of those parameters again, but not all.
Note! This action is not supported on all devices, so you should also check for ActivityNotFoundException when you start the activity, find an alternative way to crop on those devices or ask the user to install an app for that such as QuickPic.