I want to crop an image in my application when it is selected from gallery. i.e if I launch the gallery and select an image the cropping window should come like when we sele
Although part of the internal API, the com.android.camera.action.CROP
seems like it is well-supported on most Android devices. This might get you started:
final Intent intent = new Intent("com.android.camera.action.CROP");
intent.setData(uriOfImageToCrop);
intent.putExtra("outputX", 400);
intent.putExtra("outputY", 400);
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("scale", true);
intent.putExtra("noFaceDetection", true);
intent.putExtra("output", Uri.fromFile(someOutputFile));
startActivityForResult(intent, SOME_RANDOM_REQUEST_CODE);
Then handle what you need to do in the onActivityResult()
method of your Activity
. Your output file should be the cropped image.
Since this Intent
action is part of the internal API, however, I would strongly advise that you have some sort of fallback behavior if some device does not support the Intent
. Some manufacturers provide their own Gallery apps and so there is no way of knowing whether or not the user's device will recognize the Intent
. PLEASE DON'T FORGET THIS!! :)