我的应用程序支持从图库中选择图像,它适用于大多数设备。 我到目前为止与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);
}
答案 0 :(得分:0)
我使用glide库来处理此问题。
->with('main_content', $manage);