Android位图质量问题 [英] Android bitmap quality issues

查看:23
本文介绍了Android位图质量问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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 有点类似于 调整/缩放位图后图像质量不佳

question is somewhat similar to Bad image quality after resizing/scaling bitmap

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

try disabling scaling, resize in an offscreen bitmap and make sure that Bitmap is 32 bits (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

这篇关于Android位图质量问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆