How to get raw raster image sizes in ImageView?

It seems like I could ignore something obvious, but I can't figure out how to get the raw (unscaled) sizes of the bitmap displayed in the ImageView.

For example, if I load a bitmap using Bitmap b = BitmapFactory.decodeResource(...), I can get these sizes from b.getWidth()and b.getHeight(), and I could pass the bitmap to ImageView using setImageBitmap(b). But if I have a subclass of ImageView, is there a way to get these dimensions without passing them explicitly? I guess I'm looking for an analog getImageBitmap()method of the ImageView setImageBitmap(), which will extract the Bitmap object that I can call getWidth()and getHeight()on. Any other way to get the original sizes will work too.

0
source share
1 answer

You can use the getDrawable () getIntrinsicHeight () command, I think that would do the trick. See the SDK documentation here .

+1
source

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


All Articles