将此图像上传到服务器时。它旋转了 90 度。这是图片的链接:
https://drive.google.com/file/d/0Bw8vnOWKrLfgWElsRW81SmxXeDA/view?usp=sharing
这是检查方向的代码。但它没有检测到旋转:
/**
* get image matrix rotation by uri
*/
private static Matrix matrixUriImgRotation(Uri uri) {
Log.i("imageRotatin", "image rotation called");
ExifInterface exif = null;
try {
exif = new ExifInterface(uri.getPath());
} catch (Exception e) {
Log.i("imageRotatin", "exception:" + e.getMessage());
}
//get image rotation
int exifRotation = 0;
if (exif != null) {
exifRotation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
Log.i("imageRotatin", "exif not null");
}
//convert exif rotation to degrees
int rotationInDegrees = 0;
if (exifRotation == ExifInterface.ORIENTATION_ROTATE_90) {
rotationInDegrees = 90;
} else if (exifRotation == ExifInterface.ORIENTATION_ROTATE_180) {
rotationInDegrees = 180;
} else if (exifRotation == ExifInterface.ORIENTATION_ROTATE_270) {
rotationInDegrees = 270;
}
//build matrix
Matrix matrix = new Matrix();
if (exifRotation != 0) {
Log.i("imageRotatin", "rotationInDegree:" + rotationInDegrees);
matrix.preRotate(rotationInDegrees);
}
return matrix;
}
注意:其他图片上传没有问题。