【发布时间】:2016-01-06 09:08:24
【问题描述】:
我的应用支持从图库中挑选图片,它适用于大多数设备。 到目前为止,我对 LG g4 和三星 Galaxy s6 有疑问: 从手机相机拍摄的每张图像都将旋转保存,其 exif 参数保持为 0。当我从手机图库中选择此图像时,它将返回旋转图像(90 度),但 exif 参数为 0。
try {
ExifInterface exif = new ExifInterface(data.getPath());
int rotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_UNDEFINED);
int rotationInDegrees = exifToDegrees(rotation);
if (rotationInDegrees == 0)
chosenImage = RotateBitmap(chosenImage, 0);
else if (rotationInDegrees == 90)
chosenImage = RotateBitmap(chosenImage, 90);
else if (rotationInDegrees == 270)
chosenImage = RotateBitmap(chosenImage, 270);
} catch (IOException e) {
e.printStackTrace();
}
exifToDegrees(旋转):
private static int exifToDegrees(int exifOrientation) {
if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_90) {
return 90;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_180) {
return 180;
} else if (exifOrientation == ExifInterface.ORIENTATION_ROTATE_270) {
return 270;
}
return 0;
}
rotateBitmap(位图):
public static Bitmap RotateBitmap(Bitmap source, float angle) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix, true);
}
【问题讨论】:
-
现在有同样的问题。你解决了吗?
标签: android image bitmap rotation exif