potatoe
potatoe

Reputation: 1070

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

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.

Upvotes: 0

Views: 729

Answers (1)

PearsonArtPhoto
PearsonArtPhoto

Reputation: 39698

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

Upvotes: 1

Related Questions