Reputation: 3660
I want to crop an image , I am able to implement this.
My code is as
Intent cropIntent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
cropIntent.setDataAndType(fileUri, "image/*");
// set crop properties
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, CROP_PIC);
where fileUri
contains URI for path of image which I want to crop from Gallery.
Using this code an alert opens to choose application to select image, I am wondering while I have passed Image path already then why its asking to select application to open Image and when I select application(via Gallery) then I have to choose image from Gallery to crop.
I want a solution using which my image just opens up with crop option without asking to select application to open with ?
Is it possible? please help me to achieve it...
Upvotes: 0
Views: 1056
Reputation: 1601
Using the native crop is not good solution, because the behavior of each crop is different. I came across some errors as it is not possible to save a file, is not correct aspect ratio, maybe there are also other.
I think the best solution to use custom crop library after pick photo from gallery.
There are some good libraries with examples like https://github.com/jdamcd/android-crop or https://github.com/lvillani/android-cropimage or https://github.com/edmodo/cropper
Upvotes: 0
Reputation: 4032
Try With This:
String filename = "image.png";
String path = "/mnt/sdcard/" + filename;
File f = new File(path); //
Uri imgUri= Uri.fromFile(f);
Intent intent = new Intent("com.android.camera.action.CROP");
intent.setDataAndType(imgUri, "image/*");
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 50);
intent.putExtra("outputY", 50);
intent.putExtra("return-data", true);
startActivityForResult(intent, 1);
Upvotes: 1