Samsung mobile phone photo, select photo rotation from the image library to solve the problem perfectly, SamSung mobile phone Image Library
Recently, I have solved a headache for a long time, that is, Samsung's mobile phone camera image rotation problem. The project has the image upload function, which involves taking photos and selecting images from the album, there is no problem with other mobile phones, but after taking a photo of Samsung's mobile phone, you will clearly see that the photo will be rotated, and then the picture you find Based on the path is already rotated, the solution was finally found by me. We can read the rotation angle in the exif (Exchangeable Image File interchangeable Image File) Information Based on the Image path.
According to the debugging, we can clearly find that the rotation angle of the pictures taken by Samsung mobile phones is 90 degrees, while that of other mobile phones is 0 degrees.
Take a look at the Code:
/ **
* Read the rotation angle in photo exif information
* @param path photo path
* @returnangular
* /
public static int readPictureDegree (String path) {
int degree = 0;
try {
ExifInterface exifInterface = new ExifInterface (path);
int orientation = exifInterface.getAttributeInt (ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
degree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
degree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
degree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace ();
}
return degree;
}
So we only need to rotate the image according to the rotation angle.
public static Bitmap toturn (Bitmap img) {
Matrix matrix = new Matrix ();
matrix.postRotate (+90); / * Rotate 90 degrees * /
int width = img.getWidth ();
int height = img.getHeight ();
img = Bitmap.createBitmap (img, 0, 0, width, height, matrix, true);
return img;
}