Android Canvas DrawBitmap 质量差

Android Canvas DrawBitmap poor quality

我正在扩展 SurfaceView 以创建全屏水平滚动背景。

我的问题是位图的质量。在绘图调用中用作

canvas.drawBitmap(bitmap, 0, 0, paint);

它的质量比原来的差很多。我没有做任何缩放。

BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image, options);

Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setFilterBitmap(true);

不确定图像是否显示清楚,它们是平板电脑的屏幕截图。好的是一个 ImageView,它的 src 作为 drawable。

canvas有这种横向条纹的效果,在现实中意义重大。这种效果也是垂直的。每当渐变略有变化时。好像 canvas' 位图的颜色少得多..

我确定有解决方案,但我找不到。

Poor quality example

Real quality example

看起来像颜色量化。 SurfaceView 的默认颜色格式是 16 位 RGB_565。在 onCreate():

上用类似这样的东西将其更改为 32 位
mSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);

(Some examples 使用 PixelFormat.TRANSLUCENT。)