问题
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