gpt4 book ai didi

android - 旋转图像时会改变图像的实际位置

转载 作者:行者123 更新时间:2023-11-29 22:01:35 26 4
gpt4 key购买 nike

我尝试使用 Matrix 旋转位图,如果角度为 90 度而不是 90 度位图位置正在改变,则它工作正常。

代码 fragment :

            Matrix matrix = new Matrix();
matrix.postRotate(90);
Bitmap map= Bitmap.createBitmap(resizedBitmap, 0, 0,resizedBitmap.getWidth(), resizedBitmap.getHeight(),matrix, true);

你们能告诉我如何在不改变图像位置的情况下旋转图像吗?

谢谢。

最佳答案

如果你正在使用 ImageView,我建议为 ImageView 设置矩阵,而不是像这样每次都创建一个新的位图

              Matrix matrix=new Matrix();
img.setScaleType(ScaleType.MATRIX);
int height = img.arrow.getHeight();
int width = img.arrow.getWidth();
matrix.postRotate((float) angle, width/2,height/2);
img.setImageMatrix(matrix);

关于android - 旋转图像时会改变图像的实际位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11789679/

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