1
我创建了一个带背景旋转的旋转图像视图,但结果是“别名”。背景上的旋转图像的抗锯齿?
通常的方法是创建一个Paint
具有反别名标志,然后用它来绘制位图。 但是,背景是通过视图的draw(Canvas canvas)
方法绘制的,所以我无法使用canvas.drawBitmap
方法绘制。
这里我的代码以旋转的ImageView包括背景:
@Override
public void draw(Canvas canvas)
{
canvas.save();
canvas.rotate(mAngle%360, canvas.getClipBounds().exactCenterX(), canvas.getClipBounds().exactCenterY());
canvas.scale(scaleWidth, scaleHeight, canvas.getClipBounds().exactCenterX(), canvas.getClipBounds().exactCenterY());
super.draw(canvas);
canvas.restore();
}
和我的onMeasure方法相适应的高度,并根据该角度的
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int w = getDrawable().getIntrinsicWidth();
int h = getDrawable().getIntrinsicHeight();
double a = Math.toRadians(mAngle);
int width = (int) (Math.abs(w * Math.cos(a)) + Math.abs(h * Math.sin(a)));
int height = (int) (Math.abs(w * Math.sin(a)) + Math.abs(h * Math.cos(a)));
scaleWidth = (width != 0) ? ((float) w)/width : 1;
scaleHeight = (height != 0) ? ((float) h)/height : 1;
setMeasuredDimension(width, height);
}
所以宽度,我如何“在这个旋转上启用“anti aliasing?
见http://stackoverflow.com/questions/14378573/bitmap-not-drawn-anti-aliased/14443954#14443954 – yoah 2013-02-26 20:06:44
我已经看到了这个问题,但我的旋转也关注背景,并且背景由view.draw()方法绘制。所以我不能使用这个解决方案 – Goo 2013-02-26 20:25:23