我正在扩展 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 作为可绘制对象。
Canvas 上有这种水平条纹效果,在现实中非常重要。这种效果也是垂直的。每当渐变略有变化时。好像 Canvas 的位图颜色少得多..
我确定有解决方案,但我找不到。
最佳答案
看起来像颜色量化。 SurfaceView 的默认颜色格式是 16 位 RGB_565。在 onCreate()
上将其更改为 32 位:
mSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
(Some examples 使用 PixelFormat.TRANSLUCENT
。)
关于Android Canvas DrawBitmap 质量差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37040175/