安卓位图质量问题

5

在我的应用中,位图的颜色看起来像是一些低质量的类型。如果我使用画廊应用程序加载背景图像,则正常加载,并且不会呈现出超低质量的外观。我用来加载和绘制图像的代码很简单:

//Code for initializing the Bitmap
Bitmap bitmap = Bitmap.createScaledBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.none), (int) (canvas.getWidth() * compression), (int) (canvas.getHeight() * compression), true);
//...
//Code for drawing this Bitmap
canvas.drawBitmap(bitmap, null, new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), null);

如果代码中没有提示出错的信息,我制作了一张图片来比较在计算机或其他图像查看器上实际看起来像什么,以及在应用程序中看起来像什么。 上面的图像是手机上的应用程序,下面的图像是背景图像的真实外观。注意顶部图像上的线条。怎么回事?


坦白地说,大多数安卓设备的图形输出都很糟糕,我不确定用户是否会抱怨。 - ina
@ina也许这是因为人们在他们的应用程序中接受了不完整的解决方案,所以它看起来很糟糕。 ;) - Joakim Engstrom
1个回答

5

问题与调整/缩放位图后图像质量差类似。

尝试禁用缩放,在离屏位图中调整大小,并确保位图为32位(ARGB888):

Options options = new BitmapFactory.Options();
options.inScaled = false;
options.inDither = false;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap source = BitmapFactory.decodeResource(a.getResources(), path, options);

关于图像缩放/处理的另一个好而完整的答案可以在Quality problems when resizing an image at runtime找到。


请告诉我 "a.getResources()" 是什么意思,其中 a=? - Anil M H
activity::getResources() - goRGon

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接