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

标签 android matrix bitmap image-rotation

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

相关文章:

r - 根据日期合并长格式的两个数据帧

java - 在java中按角度和轴旋转 vector

android - Vector Drawables 与 RAM 方面的位图 (Android)

c# - 如何将 1D 字节数组转换为保存位图的 2D 字节数组?

android - Android Google Play服务库,Analytics奇怪的输出

android - Android Webview文件和相机上传-Kotlin

matlab - 根据给定位置选择矩阵的条目

c# - 位图保存 jpeg 失败但 png 可以,因为注释属性

java - 有没有办法使用 InputMethodManager 强制键盘为数字?

Android support-v7 appcompat v22 Android 4 中的按钮样式和工具栏问题