Skip to content Skip to sidebar Skip to footer

Android Image Preview Example For Cropping

Many apps, such as Facebook, have this feature where after a user chooses an image from their device's gallery, the user is then brought to a preview where they can choose a croppe

Solution 1:

Try the below code, change the parameters as per your requirements:

Intent cropIntent = new Intent("com.android.camera.action.CROP");
//indicate image type and Uri
cropIntent.setDataAndType(fileUri, "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", 350);
cropIntent.putExtra("outputY", 350);
//retrieve data on return
//cropIntent.putExtra("return-data", true);
// some code to retriev an valid Uri
cropUri =  Uri.fromFile(getOutputMediaFile(MEDIA_TYPE_IMAGE));
 cropIntent.putExtra(MediaStore.EXTRA_OUTPUT, cropUri);
//start the activity - we handle returning in onActivityResult
startActivityForResult(cropIntent, CROP_REQ_CODE);

and you can get the output using in OnActivityResult()

Bundleextras= data.getExtras();
//get the cropped bitmap
clickedPhoto = extras.getParcelable("data");

Post a Comment for "Android Image Preview Example For Cropping"