Draw smoothly scaled bitmaps on Canvas

fhucho picture fhucho · Nov 27, 2010 · Viewed 43.1k times · Source

This is how I draw Bitmap on Canvas in my Android app:

canvas.save();
canvas.scale(scale, scale, x, y);
canvas.drawBitmap(bitmap, x, y, null);
canvas.restore();

However the Bitmap is not scaled smoothly, no anti-aliasing is performed. How can I enable anti-aliasing?

Answer

Vit Khudenko picture Vit Khudenko · Nov 27, 2010

Try this:

Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setFilterBitmap(true);
paint.setDither(true);

canvas.drawBitmap(bitmap, x, y, paint);