我有一张尺寸为 960x800 的图像,我试图让它填满屏幕。
我目前的做法是加载完整的 960x800 位图并使用源和目标Rect
对象。到目前为止,我的目标矩形为 480x320(屏幕尺寸),源矩形为 960x800。
background = BitmapFactory.decodeResource(getResources(), R.drawable.background, null);
destRect = new Rect(0,0, screenWidth, screenHeight);
sourceRect = new Rect(0,0, background.getWidth(), background.getHeight());
...
c.drawBitmap(background, sourceRect, destRect, backgroundPaint);
如果我然后使用Paint
当尝试画布背景时,对象并设置抖动为真,图像看起来绝对完美。
Paint backgroundPaint = new Paint();
backgroundPaint .setDither(true);
我得出的结论是,这可能不是很有效,导致每次绘图调用都完成不必要的工作。为了解决这个问题,我想尝试执行以下操作:
background = BitmapFactory.decodeResource(getResources(), R.drawable.background, null);
background = Bitmap.createScaledBitmap(background, display.getWidth(), display.getHeight(), true);
从而创建一个已经调整大小的位图,无需任何Rect
对象。但是,执行此操作时,我无法保持与使用上述方法相同的图像质量。事实上,该图像看起来与我不使用时所看到的类似。Paint
对象与上述方法。在缩放位图上使用绘制对象似乎没有效果。
举个例子来说明我的图像的外观,它类似于this http://upload.wikimedia.org/wikipedia/commons/thumb/b/be/Dithering_example_undithered_web_palette.png/225px-Dithering_example_undithered_web_palette.png图片(虽然没那么严重)
我可以做些什么来获得相同的图像质量吗?