资源质量较差的位图转换结果 [英] Resource to bitmap conversion results in poor quality
问题描述
我从来没有真正发现之前,但是当我使用setImageBitmap,使用位图是从资源利用BitmapFactory德codeD更改的ImageView的形象,那么图像的质量会下降,我不知道为什么。
I never really noticed it before but when I change the image of an imageview using setImageBitmap, using a bitmap which is decoded from resources using BitmapFactory, then the quality of image deteriorates and I don't know why.
我甚至像 options.in preferredConfig
, options.inJustDe codeBounds
, options.inDither
,但结果pretty大致相同;质量差的形象。
I even played around with BitmapFactoryOptions like options.inPreferredConfig
, options.inJustDecodeBounds
, options.inDither
, but the results were pretty much the same; a poor quality image.
在其他的如果我只是用setImageResource,图像不恶化,是质量最好的可能。
On the other if I just use setImageResource, the image doesn't deteriorates and is in best quality possible.
所以基本上这两个codeS
So basically these two codes
-
位图B = BitmapFactory.de codeResource(getResources(),R.drawable.keypad,期权); iv.setImageBitmap(BitmapFactory.de codeResource(getResources(),R.drawable.keypad))
iv.setImageResource(R.drawable.messages);
结果在不同的图像质量。
results in different image quality.
有人能解释一下为什么?而如何使用code 1解决这个问题的质量。
Can anybody explain why? And how to solve this quality issue using code 1.
推荐答案
如果您在使用 BitmapFactory.de codeResource
方法模糊的图像,你可以使用这个code:
If you have blurry images using the BitmapFactory.decodeResource
method, you can use this code:
Options options = new BitmapFactory.Options();
options.inScaled = false;
Bitmap b = BitmapFactory.decodeResource(getResources(), path, options);
iv.setImageBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.keypad));
BitmapFactory.Options
类的<code> inScaled 参数设置为false,将美元低磷$ pvent模糊图像屏幕分辨率,因为它会prevent scalling如这previous SO问题。也许你已经尝试过这一点,但我认为值得一提的。
Setting the inScaled
parameter of BitmapFactory.Options
class to false, will prevent blurry images on low screen resolutions since it will prevent scalling as mentioned in the answer of this previous SO question. Maybe you have already tried this but i thought worth mentioning.
这篇关于资源质量较差的位图转换结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!