带背景的旋转图像上的抗锯齿?

时间:2013-02-26 19:59:39

标签: android android-imageview image-rotation

我创建了一个带有背景旋转的旋转图像视图,但结果是“别名”。

通常的方法是创建一个带有反别名标志的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);
}

那么,如何在此旋转中“启用”抗锯齿?

1 个答案:

答案 0 :(得分:1)

也许在画布上使用setDrawFilter?

  

DrawFilter子类可以安装在Canvas中。当它存在时,它可以修改用于绘制(暂时)的绘画。有了这个,过滤器可以禁用/启用抗锯齿,或更改绘制的所有内容的颜色。

编辑:点击此处:https://stackoverflow.com/a/13191948/1954497

相关问题