Android: crop image to specific size

My intention is for the user to select an image from the gallery, and then proceed with cropping. However, I need a rectangle that defines the cropping mask that needs to be locked for a particular dimension, and then the user simply repositions it to display part of the image.

Any ideas on how this will be done?

thanks

-T

+4
source share
2 answers
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()); 
+15
source

You need to create a custom ImageView class to achieve scaling and panning of the image and may have a fixed image(transparent) rectangle superimposed on that image. And can create a sub-image of this bitmap. and save it to a file.

 createBitmap(Bitmap source, int x, int y, int width, int height); 

This method is used to create a beat map.

http://blog.sephiroth.it/2011/04/04/imageview-zoom-and-scroll/

After achieving zooming and panning, I'm not sure that createBitmap can create a sub-image from the visible part of the image (i.e., part of the image will not be visible on the screen when it is enlarged). So try to get drawingCache() from ImageView and create a padded image for the same.

+6
source

Source: https://habr.com/ru/post/1397712/


All Articles