我尝试使用 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/