顺利缩放位图这是我在我的Android应用程序上Canvas
画Bitmap
:在画布上绘制
canvas.save();
canvas.scale(scale, scale, x, y);
canvas.drawBitmap(bitmap, x, y, null);
canvas.restore();
然而Bitmap
不顺利缩放,不执行抗锯齿。我如何启用抗锯齿?
顺利缩放位图这是我在我的Android应用程序上Canvas
画Bitmap
:在画布上绘制
canvas.save();
canvas.scale(scale, scale, x, y);
canvas.drawBitmap(bitmap, x, y, null);
canvas.restore();
然而Bitmap
不顺利缩放,不执行抗锯齿。我如何启用抗锯齿?
试试这个:
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);
canvas.drawBitmap(bitmap, x, y, paint);
您是否尝试过创建Paint
对象,调用setAntiAlias(true)
并将它作为第四个参数传递给drawBitmap
方法?如果这不起作用,我想你应该缩减drawBitmap
的调用,而不是缩放画布,例如通过使用drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint)
。
两个Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG);
或paint.setFilterBitmap(true);
为我工作,但要非常小心,我的比赛就砍下了FPS从30FPS
只17FPS
。因此,如果它是像游戏一样的任务关键绘图,那么您最好在加载时缩放图像。我照做了以下方式:
public Bitmap getImage (int id, int width, int height) {
Bitmap bmp = BitmapFactory.decodeResource(getResources(), id);
Bitmap img = Bitmap.createScaledBitmap(bmp, width, height, true);
bmp.recycle();
return img;
}
用途:
canvas.drawBitmap(source, 0, 0, new Paint(Paint.ANTI_ALIAS_FLAG));
刚一说明。如果你只需要一个平方的结果,无论你需要放大或缩小,使用这个令人难以置信的方便的技巧... stackoverflow.com/a/17733530/294884希望它可以帮助别人 – Fattie 2014-06-02 13:43:45