Friday, August 27, 2010

ImageCrop in android

AIM: To  crop the Image in android.
Solution:
The main thing  is open gallery with the intent to Crop the image.
as

    Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null);
           intent.setType("image/*");
           intent.putExtra("crop", "true");
           intent.putExtra("aspectX", aspectX);
           intent.putExtra("aspectY", aspectY);
           intent.putExtra("outputX", outputX);
           intent.putExtra("outputY", outputY);
           intent.putExtra("scale", scale);
           intent.putExtra("return-data", return_data);
           intent.putExtra(MediaStore.EXTRA_OUTPUT, getTempUri());
           intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());
           intent.putExtra("noFaceDetection",!faceDetection); // lol, negative boolean noFaceDetection
           if (circleCrop) {
            intent.putExtra("circleCrop", true);
           }
         
           startActivityForResult(intent, PHOTO_PICKED);

You can download the entire project here by clicking DOWNLOAD PHOTO CROP CODE.

If any problems let me know.


4 comments:

  1. Thanks for the snippets ,
    This code is not working on Motorola Atrix(android-2.3.6) .Is there any external parameter that i need to pass ??

    ReplyDelete
  2. is there any way, that allow us to open specific image for cropping, rather than selecting from gallery

    ReplyDelete
    Replies
    1. i am looking for the same thing, you are asking here.
      pleae reply me on coolhtarksheel@gmail.com, if you have found any way...???

      Delete
  3. How to pass bitmap to another activity? Need help. Please

    ReplyDelete

Android Developers Blog

Ram's shared items