Android位图质量问题

Moh*_*dib 5 android bitmap

在我的应用程序中,绘制位图就好像颜色是一些较低质量的类型.如果我使用图库应用程序加载背景图像,它加载很好,看起来不是它的超低质量.我用来加载和绘制图像的代码很简单:

//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);
Run Code Online (Sandbox Code Playgroud)

如果代码中没有任何内容告诉您出了什么问题,我制作了一个图像,比较图像在计算机或其他图像查看器上的实际外观,以及它在应用程序中的外观. 顶部图像是手机上的应用程序,底部图像是背景图像的实际外观. 注意顶部图像上的线条. 怎么了?

Shi*_*ine 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);
Run Code Online (Sandbox Code Playgroud)

关于图像缩放/处理的另一个好的和完整的答案可以在运行时调整图像大小时的质量问题中找到