Recently solved a problem that has been troubling me for a long time. Samsung mobile phone Photo picture rotation problem, the project has the function of uploading pictures, then involves taking photos, choose pictures from the album, other mobile phones are ok no problem, but Samsung's mobile phone photos, you will be very clear to see the photos will rotate, Then you find the image according to the path has been rotated, the solution finally I found. We can read the image from the path of the photo exif (exchangeable image File interchange images) information in the rotation angle, as for this EXIF can look at Daniel's article
Android under the EXIF
According to the debugging, it can be clearly found that Samsung mobile phone photos of the rotation angle is 90 degrees, while the other mobile phone rotation angle is 0 degrees
Take a look at the code:
/**
* Read the rotation angle in the photo EXIF information
* @param path photo paths
* @return Angle * * 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 =;
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 just need to rotate the picture from the angle of rotation.
public static Bitmap Toturn (Bitmap img) {
Matrix matrix = new Matrix ();
Matrix.postrotate (+90); /* Flip 90 degrees *
/int width = img.getwidth ();
int height =img.getheight ();
img = Bitmap.createbitmap (img, 0, 0, width, height, matrix, true);
return img;
}
Easy to solve, isn't it perfect?
The above is the entire content of this article, I hope you like.