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

问题描述 投票:0回答:1

我正在拍照,将其保存为文件并显示它,因为你可以看到主要的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

android kotlin imageview android-bitmap
1个回答
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

© www.soinside.com 2019 - 2024. All rights reserved.