How do I get the raw dimensions of a bitmap in an ImageView?

谁都会走 提交于 2020-01-06 08:12:20

问题


It seems like I might be overlooking something obvious, but I can't figure out how to retrieve the raw (unscaled) dimensions of a bitmap being displayed in an ImageView.

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


回答1:


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



来源:https://stackoverflow.com/questions/4524263/how-do-i-get-the-raw-dimensions-of-a-bitmap-in-an-imageview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!