Crop image using intent in android

Crop image using intent in android

This is the sample program for crop the selected image using intent in startActivityResult in android.

Follow the simple step to crop the selected image.

1. StartActivityResult for pick the photo from the Camera or from file location.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);mImageCaptureUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(),
“tmp_avatar_” + String.valueOf(System.currentTimeMillis()) + “.jpg”));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mImageCaptureUri);
try {
intent.putExtra(“return-data”, true);
startActivityForResult(intent, PICK_FROM_CAMERA);
} catch (ActivityNotFoundException e) {
} else { //pick from file
Intent intent = new Intent();
startActivityForResult(Intent.createChooser(intent, “Complete action using”), PICK_FROM_FILE);

2. After get the photo ,thenStartActivityResult for crop the selected image using,

final ArrayList<CropOption> cropOptions = new ArrayList<CropOption>();
Intent intent = new Intent(“”);
List<ResolveInfo> list = getPackageManager().queryIntentActivities( intent, 0 );
int size = list.size();
if (size == 0) {
Toast.makeText(this, “Can not find image crop app”, Toast.LENGTH_SHORT).show();
} else {
intent.putExtra(“outputX”, 400);
intent.putExtra(“outputY”, 400);
intent.putExtra(“aspectX”, 1);
intent.putExtra(“aspectY”, 1);
intent.putExtra(“scale”, true);
intent.putExtra(“return-data”, true);
if (size == 1) {
Intent i = new Intent(intent);
ResolveInfo res = list.get(0);
i.setComponent( new ComponentName(res.activityInfo.packageName,;
startActivityForResult(i, CROP_FROM_CAMERA);
3. That will return the cropped image .get the cropped image and make use of it.
Bundle extras = data.getExtras();
if (extras != null) {
Bitmap photo = extras.getParcelable("data");


Crop image using Intent
Crop image
Crop image


1 thought on - Crop image using intent in android

  • tq so much,
    keep it up

Leave a Reply

Your email address will not be published. Required fields are marked *