I have a problem regarding cropping image in android studio, whenever I run this cropping code on my device or any other One-plus device, it runs efficiently. But other devices like Redmi, Samsung, Motorola, crash after reaching this cropping part. if I comment out the function call to the cropping function, it runs smoothly on all devices but at cost of non-availability of cropping
public void ImageCropFunction(Uri uri) {
// Image Crop Code
try {
Intent CropIntent = new Intent("com.android.camera.action.CROP");
Toast.makeText(getContext(),"plz, Crop the Required part",Toast.LENGTH_LONG).show();
CropIntent.setDataAndType(uri, "image/*");
CropIntent.putExtra("crop", "true");
CropIntent.putExtra("outputX", 1024);
CropIntent.putExtra("outputY", 1024);
CropIntent.putExtra("return-data", true);
CropIntent.putExtra("return-uri", uri.toString());
startActivityForResult(CropIntent, 222);
}catch (ActivityNotFoundException e) {
}
}
2
Answers
Android does not have a
CROP
Intent
. There is no requirement for any device to support that undocumentedIntent
, let alone with those undocumented extras. There are dozens of libraries for image cropping. Please use one.What to use
You can use uCrop library.
Implemention
Make sure you have this line in your
settings.gradle
Add it to your
build.gradle
.Then you should add it to your manifest
How to use
You can crop a image like this
Get the result
You can fetch the result in the
onActivityResult
like thisOutput
View the output gif from here