Search code examples
androidbitmapimageviewscale

How to crop visible part of a bitmap in an ImageView if it is scaled


Assume I have an image which is larger than an ImageView size (width and height) and the scaleType is set to CENTER or the scaleType is set to MATRIX and the bitmap is translated and scaled. Therefore parts of the image are not visible. How may I calculate the visible part of the bitmap and crop exact that part. I want to crop and store only the visible part.

How may I do that?

Any help will be appreciated.


Solution

  • So you want exactly what the image view shows? I'd enable the drawing cache and grab it from the view. That should be exactly what's on screen.