user1293519 user1293519 - 4 months ago 69x
Android Question

Crop an image when selected from gallery in android

I want to crop an image in my application when it is selected from gallery.
i.e if I launch the gallery and select an image the cropping window should come like when we select an image from iPhone. Is it possible in Android.

I found one tutorial for cropping the image in android, but dont seem the way I wanted.


Yes it's possible to crop image in android by using after picking image url from will start Crop Editor as:

Intent intent = new Intent("");  
intent.setClassName("", "");  
File file = new File(filePath);  
Uri uri = Uri.fromFile(file);  
intent.putExtra("crop", "true");  
intent.putExtra("aspectX", 1);  
intent.putExtra("aspectY", 1);  
intent.putExtra("outputX", 96);  
intent.putExtra("outputY", 96);  
intent.putExtra("noFaceDetection", true);  
intent.putExtra("return-data", true);                                  
startActivityForResult(intent, REQUEST_CROP_ICON);

When the picture select Activity return will be selected to save the onActivityResult:

Bundle extras = data.getExtras();  
if(extras != null ) {  
    Bitmap photo = extras.getParcelable("data");  
    ByteArrayOutputStream stream = new ByteArrayOutputStream();  
    photo.compress(Bitmap.CompressFormat.JPEG, 75, stream);  
        / / The stream to write to a file or directly using the

and see this post which is also help you for cropping image in android