开发者

The way to calculate Bitmap size?

I'm trying to find the size of my image but not to load into memory. I use the flowing code

BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeResource(a.getResources(), R.drawable.icon, o);
int width1 = o.outWidt;     
int height1 = o.outHeight;

Now开发者_如何学Go, I make some comparison:

Bitmap icon = BitmapFactory.decodeResource(a.getResources(), R.drawable.icon);
int width = icon.getWidth();
int height = icon.getHeight();

Why width, height is not equal to width1 and height1 ?


I'm almost certain this is because referencing that image from resources with decode the image comes pre scaled for density.

Checkout #1 here on the docs: http://developer.android.com/guide/practices/screens_support.html#DensityConsiderations


I'm not sure what is going on, but it may be that BitmapFactory applies density scaling when actually returning a bitmap (as described here), but not when it is just decoding its size. (If this is what's going on, I'd consider filing a bug report.)

You can test this theory by moving your image from the drawables directory to drawables-nodpi.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜