Search code examples
androidimageimage-processingcameracrop

Android: Cropping an image to specific size


My intention is to have the user pick an image from the gallery, then have a cropping activity come up. However, I need the rectangle that defines the cropping mask to be locked to a certain dimension and then the user simply repositions it to display a portion of an image.

Any ideas on how this would be done?

Thanks

-T


Solution

  • Intent intent = new Intent(Intent.ACTION_GET_CONTENT, null)
                .setType("image/*")
                .putExtra("crop", "true")
                .putExtra("aspectX", width)
                .putExtra("aspectY", height)
                .putExtra("outputX", width)
                .putExtra("outputY", height)
                .putExtra("scale", true)
                .putExtra("scaleUpIfNeeded", true)
                .putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f))
                .putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString());