位图宽度/高度不同的资源加载后 [英] Bitmap width/height different after loading from Resource

查看:167
本文介绍了位图宽度/高度不同的资源加载后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1。我'新到Android编码:)

1st. i'am new to Android coding :)

我做的是我从我的资源加载位图/绘制-MDPI以

What I do is I load an Bitmap from my res/drawable-mdpi with

BitmapFactory.decodeResource(getResources(), R.drawable.cat_ground_01);

我注销位图的宽度/高度后,它告诉我的其他值,则位图真的是。

after I Log out the width/height of the Bitmap it tells me an other value then the Bitmap realy is.

这还挺困难的地方位图pixelperfect例如重叠与嘴的位图的脸的位图。

That's kinda difficult to place Bitmaps pixelperfect e.g. overlap a bitmap of an face with an bitmap of mouth.

也许我'只是缺少这个主题的一些知识:9
我希望你能有所帮助。

maybe I'am just missing some knowledge for this Topic :9 I hope you can help.

推荐答案

当你做Bitmapfactory.de codeResource(),Android的默认情况下会选择匹配DPI版本脱code,会发生什么在你提到的code将得到:

When you do Bitmapfactory.decodeResource(), Android by default will choose the "matched" dpi version to decode, what happen in your mentioned code will yields:


  1. 您不能指定它是否在MDPI,华电国际也好,它会选择符合您正在运行的系统的版本。即,如果你是一个MDPI设备上运行,它会去code中的MDPI版本;在LDPI,那么LDPI版本。

  1. You can't specify whether it is in mdpi, hdpi or whatever, it will choose the version that match your running System. i.e., if you are running on a mdpi device, it will decode the mdpi version; in ldpi, then the ldpi version.

假设你使用的是华电国际的设备,但没有MDPI资源的定义,它的作用是把你的MDPI的资源,去code中,这将使它成为华电国际(也就是说,它放大您MDPI位约1.5倍大);再次,如果您的设备具有较低的分辨率,然后将缩小图像

Suppose you are using a hdpi device, but no mdpi resource is defined, what it will do is take your mdpi resource, and during decode, it will make it into hdpi (i.e., it enlarge your mdpi bitmap to about 1.5x larger); again, if your device has lower resolution then it will shrink the image

我想这是发生在你身上。对于BitmapFactory,它实际上有选择不缩放图像:

I guess this is what happens to you. For BitmapFactory, it actually has the option to NOT scaling the image:

<一个href=\"http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html\">http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html

设置inScaled假就行了。

Set the inScaled to false will do.

这篇关于位图宽度/高度不同的资源加载后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆