gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 03:45:22 27 4
gpt4 key购买 nike

我创建了一个带有背景旋转的旋转 ImageView ,但结果是“混叠”。

通常的方法是创建一个带有反锯齿标志的Paint,然后用它来绘制位图。但是,背景是由 View 的 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);
}

那么,我怎样才能在这个旋转中“启用”抗锯齿?

最佳答案

也许在 Canvas 上使用 setDrawFilter?

A DrawFilter subclass can be installed in a Canvas. When it is present, it can modify the paint that is used to draw (temporarily). With this, a filter can disable/enable antialiasing, or change the color for everything this is drawn.

编辑:看这里:https://stackoverflow.com/a/13191948/1954497

关于android - 带背景的旋转图像抗锯齿?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15098142/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com