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);
Paint.setAntiAlias()
is for text.
You want p.setFilterBitmap(true)
;.
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With