Reputation: 1563
I found quite a few threads on that topic, but unfortunately none with an answer for this problem. I want to crop an image with an unspecified size and finally save to new Image.
What I do at the moment (for better viewing I left out the try/catch etc):
Intent cropIntent = new Intent("com.android.camera.action.CROP");
cropIntent.setDataAndType(picUri, "image/*");
cropIntent.putExtra("crop", "true");
cropIntent.putExtra("outputX", 360);
cropIntent.putExtra("outputY", 360);
cropIntent.putExtra("return-data", true);
startActivityForResult(cropIntent, PIC_CROP);
I don't know if the user wants a quadrat 360x360 or maybe a rectangle 1024x768 etc. Is there any possibility to not specify outputx/Y with a fixed value?
Upvotes: 1
Views: 2328
Reputation: 21805
Use this library to crop image instead.
https://github.com/biokys/cropimage
Code from github source
// create explicit intent
Intent intent = new Intent(this, CropImage.class);
// tell CropImage activity to look for image to crop
String filePath = ...;
intent.putExtra(CropImage.IMAGE_PATH, filePath);
// allow CropImage activity to rescale image
intent.putExtra(CropImage.SCALE, true);
// if the aspect ratio is fixed to ratio 3/2
intent.putExtra(CropImage.ASPECT_X, 3);
intent.putExtra(CropImage.ASPECT_Y, 2);
// start activity CropImage with certain request code and listen
// for result
startActivityForResult(intent, REQUEST_CODE_CROP_IMAGE);
Upvotes: 2