我有一个大小为320x480
的Bitmap
,我需要将其在不同的设备屏幕上拉伸,我尝试使用了这个方法:
Rect dstRect = new Rect();
canvas.getClipBounds(dstRect);
canvas.drawBitmap(frameBuffer, null, dstRect, null);
它可以工作,图像填满了整个屏幕,就像我想要的那样,但图像很模糊,看起来很糟糕。然后我尝试了:
float scaleWidth = (float) newWidth / width;
float scaleHeight = (float) newHeight / height;
Matrix matrix = new Matrix();
matrix.postScale(scaleWidth, scaleHeight);
Bitmap resizedBitmap = Bitmap.createBitmap(frameBuffer, 0, 0,
width, height, matrix, true);
canvas.drawBitmap(resizedBitmap, 0, 0, null);
这次看起来非常完美、流畅,但是这段代码必须在我的主游戏循环中运行,并且每次迭代都创建Bitmap
使其变得非常缓慢。我如何调整图像大小,以便它不会变得模糊并且能够快速完成?
找到了解决方案:
Paint paint = new Paint();
paint.setFilterBitmap();
canvas.drawBitmap(bitmap, matrix, paint);