为什么BitmapFactory.de codeResource缩放图片? [英] Why does BitmapFactory.decodeResource scale my image?
问题描述
我有一个形象,是120x120px位于我的 / RES /绘制/
目录。这是必需的所有设备的大小。
I have an image that is 120x120px located in my /res/drawable/
directory. This is the size required for all devices.
要,我现在用的是以下加载此位图:
To load this Bitmap, I am using the following:
Bitmap tmpBmp = BitmapFactory.decodeResource(getResources(), R.drawable.myimage);
问题是,当我衡量 tmpBmp
,大小为360x360px。我知道如何扩大这一回落到我需要的120×120,但它是一种浪费的处理时间,但最小的。
The issue is that when I measure tmpBmp
, the size is 360x360px. I know how to scale this back down to the 120x120 that I need, but it is a waste of processing time, although minimal.
我假设,这已经是与屏幕密度,因为我的资源是一个密度较少的目录。
I am assuming that this has something to do with screen densities, since my resource is in a density-less directory.
什么是德codeResource 缩放我的形象的原因?我如何这样做阻止它?
What is the reason for decodeResource
scaling my image? And how do I stop it from doing so?
推荐答案
默认绘制
目录假定图像需要从默认的比例 MDPI
尺寸。把你的图片在绘制-nodpi
如果要禁用资源扩展。
The default drawable
directory assumes that images need to be scaled from the default mdpi
size. Put your images in drawable-nodpi
if you want to disable resource scaling.
别注意,120x120px图象,如果显示在屏幕上,将3倍小的xxhdpi设备上相比,MDPI装置(如有三倍每英寸为许多像素)。
Do note that a 120x120px image, if displayed on the screen, will be 3x smaller on a xxhdpi device compared to a mdpi device (as there are three times as many pixels per inch).
这篇关于为什么BitmapFactory.de codeResource缩放图片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!