当我使用bitmap.copy()时,位图的方向发生变化

时间:2019-02-28 15:22:50

标签: android kotlin imageview android-bitmap

我正在拍照,将其保存为文件并显示为imageView主画面,然后使用:

val filteredImage = bitmap.copy(Bitmap.Config.ARGB_8888,true)

我使用此filteredImage变量在图像上应用滤镜,因为它现在是可变的。

问题是:正如您在下面的小图像中所见,方向发生了变化,我进行了很多搜索,但找不到任何解决方法。

Image From the App

当我将主ImageView的位图替换为复制的位图时,我得到了:

The main <code>ImageView</code>'s bitmap orientation changed

1 个答案:

答案 0 :(得分:2)

您的原始图像可能具有Exif方向数据,这些数据丢失在bitmap.copy()上。

@Override
public void onPictureTaken(CameraView cameraView, byte[] data) {
            // Find out if the picture needs rotating by looking at its Exif data
            ExifInterface exifInterface = new ExifInterface(new ByteArrayInputStream(data));
            int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
            int rotationDegrees = 0;
            switch (orientation) {
                case ExifInterface.ORIENTATION_ROTATE_90:
                    rotationDegrees = 90;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_180:
                    rotationDegrees = 180;
                    break;
                case ExifInterface.ORIENTATION_ROTATE_270:
                    rotationDegrees = 270;
                    break;
            }
            // Create and rotate the bitmap by rotationDegrees
}

请查看以下详细信息: https://stackoverflow.com/a/20480741/1159507

相关问题