Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drawing rotated bitmap with anti alias

I tried to paint a rotated bitmap with anti alias turned on, but it still has alias and it's not smooth, any help?

I did as following:

final Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
p.setAntiAlias(true);
canvas.rotate(-mValues[0]);
canvas.drawBitmap(compass, -compass.getWidth()/2,-compass.getHeight()/2,p);
like image 739
AVEbrahimi Avatar asked Jan 19 '12 13:01

AVEbrahimi


2 Answers

Paint.setAntiAlias() is for text.

You want p.setFilterBitmap(true);.

like image 94
Reuben Scratton Avatar answered Sep 21 '22 20:09

Reuben Scratton


In case you're rotating without a canvas (with createBitmap), set filter to true.

Example:

private static Bitmap rotateBitmap(Bitmap srcImage, float angle) {

    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    Bitmap rotated = Bitmap.createBitmap(srcImage, 0, 0, srcImage.getWidth(), srcImage.getHeight(), matrix, true/*set true for anti-alias*/);
    srcImage.recycle(); // discard original image

    return rotated;
}
like image 22
lenooh Avatar answered Sep 20 '22 20:09

lenooh