简体   繁体   English

Android位图质量问题

[英]Android bitmap quality issues

In my app, the bitmap is drawn as if the color is some lower quality type. 在我的应用程序中,位图的绘制就像颜色是某种较低质量的类型一样。 If i load up the background image using the gallery app, it loads just fine and does not look like it's super low quality. 如果我使用图库应用程序加载背景图像,则它加载得很好,并且看起来不像是超低质量。 The code i am using to load and draw my images is simple: 我用来加载和绘制图像的代码很简单:

//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);

If nothing in the code tells you what is wrong, i made an image comparing what the image actually looks like on a computer or other image viewer, and what it looks like in the app. 如果代码中没有任何内容告诉您什么地方出了问题,我制作了一张图像,将图像在计算机或其他图像查看器上的实际外观与应用程序中的外观进行了比较。 顶部图片是手机上的应用,底部图片是背景图片的实际外观。注意顶部图像上的线条。这是怎么回事?

question is somewhat similar to Bad image quality after resizing/scaling bitmap 问题有点类似于调整大小/缩放位图后的图像质量差

try disabling scaling, resize in an offscreen bitmap and make sure that Bitmap is 32 bits (ARGB888): 尝试禁用缩放,在屏幕外的位图中调整大小,并确保位图为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);

another good and complete answer about image scaling/processing can be found at Quality problems when resizing an image at runtime 在运行时调整图像大小时,质量问题中可以找到关于图像缩放/处理的另一个很好的完整答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM