gpt4 book ai didi

java - 如何在 Android 上旋转 Canvas 上的位图而不使其变形

转载 作者:行者123 更新时间:2023-12-01 07:06:30 25 4
gpt4 key购买 nike

我使用矩阵在 Canvas 上旋转位图,如下所示:

public void drawRotatedPixmap(Bitmap bitmap, int x, int y, int srcX, int srcY, int srcWidth, int srcHeight, int degrees)
{
srcRect.left = srcX;
srcRect.top = srcY;
srcRect.right = srcX + srcWidth;
srcRect.bottom = srcY + srcHeight;

dstRect.left = x;
dstRect.top = y;
dstRect.right = x + srcWidth;
dstRect.bottom = y + srcHeight;

matrix.reset();
matrix.setRotate(degrees, x+srcWidth/2, y+srcHeight/2);

canvas.setMatrix(matrix);
canvas.drawBitmap(bitmap, srcRect, dstRect, null);
canvas.setMatrix(null);
}

原始位图图像非常像素化,旋转它我得到这个:

enter image description here

通过这种方式,图像会重新缩放并且边缘非常明显。我得到的结果如下:

enter image description here

可以通过在 Canvas 上绘图来完成此操作还是应该使用 openGL?

注意: Sprite 图像仅用于测试,取自 google

最佳答案

要获得更高的质量,请使用经过过滤的涂料:

Paint filterPaint = new Paint();
filterPaint.setFilterBitmap(true);
canvas.drawBitmap(bitmap, srcRect, dstRect, filterPaint);

关于java - 如何在 Android 上旋转 Canvas 上的位图而不使其变形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22582904/

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