Drawing rotated bitmap with anti alias

2019-04-06 01:21发布

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);

2条回答
一纸荒年 Trace。
2楼-- · 2019-04-06 01:55

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;
}
查看更多
霸刀☆藐视天下
3楼-- · 2019-04-06 02:01

Paint.setAntiAlias() is for text.

You want p.setFilterBitmap(true);.

查看更多
登录 后发表回答