Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Canvas.DrawBitmap without blurring/AntiAliasing?

Tags:

java

android

I'm trying to make an android game using sprites, (or very pixelated characters, backgrounds etc.). I draw them on the canvas like so...

matrix.preScale(xrat,yrat);

canvas.drawBitmap(img, matrix, null);

Where img is the Bitmap and the xrat and yrat are the scales.

My problem is that when I test, the Bitmap is blurry or anti-aliased, is there a way to prevent this? The rigid-blocky art style of the game will be ruined if the blocks are blurry.

Any (ANY) help appreciated!

like image 837
seveibar Avatar asked Dec 31 '10 20:12

seveibar


1 Answers

Create a new Paint to use when drawing the bitmaps with the settings:

Paint drawPaint = new Paint();
drawPaint.setAntiAlias(false);
drawPaint.setFilterBitmap(false);

Filtering I believe is on by default and will attempt to smooth out bitmaps when drawn scaled up.

like image 183
Kleptine Avatar answered Oct 19 '22 23:10

Kleptine