当我使用 bitmap.copy() 时,位图的方向发生变化
The bitmap's orientation changes when I use bitmap.copy()
我正在拍照,将其保存为文件并显示它,如您所见,主要 imageView
,然后我使用:
val filteredImage = bitmap.copy(Bitmap.Config.ARGB_8888,true)
我使用这个 filteredImage
变量对图像应用滤镜,因为它现在是可变的。
问题是:正如您在下面的小图片中看到的那样,方向发生了变化,我搜索了很多但找不到任何解决方案。
当我用复制的位图替换主 ImageView
的位图时,我得到了这个:
您的原始图像可能包含 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
}
详情请看这里:
我正在拍照,将其保存为文件并显示它,如您所见,主要 imageView
,然后我使用:
val filteredImage = bitmap.copy(Bitmap.Config.ARGB_8888,true)
我使用这个 filteredImage
变量对图像应用滤镜,因为它现在是可变的。
问题是:正如您在下面的小图片中看到的那样,方向发生了变化,我搜索了很多但找不到任何解决方案。
当我用复制的位图替换主 ImageView
的位图时,我得到了这个:
您的原始图像可能包含 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
}
详情请看这里: