我如何在ImageView的位图的原始尺寸是多少? [英] How do I get the raw dimensions of a bitmap in an ImageView?
问题描述
好像我可能会被忽视的东西很明显,但我无法弄清楚如何检索位图的原始(无标度)的尺寸显示在一个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.
例如,如果我用位图B = BitmapFactory.de codeResource加载一个位图(...)
,我可以从<$ C让那些尺寸$ C> b.getWidth()和 b.getHeight()
,我可以通过使用位图到一个ImageView的 setImageBitmap(二)
。但是,如果我有ImageView的子类,有没有什么方法来检索这些尺寸,而无需通过他们在明确?我想我在寻找的ImageView setImageBitmap()
方法的 getImageBitmap()
模拟,这将获取一个位图对象,我可以打电话的getWidth()
和的getHeight()
上。任何其他方式来获取原始尺寸将工作太,虽然。
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.
推荐答案
您可以使用getDrawable()。getIntrinsicHeight()命令,我认为会做的伎俩。见SDK文档<一个href=\"http://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicHeight%28%29\"相对=nofollow>这里。
You could use the getDrawable().getIntrinsicHeight() command, I think that would do the trick. See SDK documentation here.
这篇关于我如何在ImageView的位图的原始尺寸是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!