Reprinted blog: http://blog.csdn.net/walker02/article/details/8211628
A problem encountered in the development of the project, Samsung mobile phone photos in the selection of images appear abnormal, the study found that should be mobile phone shots of the picture rotated 90 degrees, some pictures rotated 180 degrees, some phones are normal. In the forum found a method, you can get the properties of the picture, read the picture rotation angle.
/**
* Read image properties: angle of rotation
* @param path image absolute path
* @return degree angle of rotation
*/
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;
}
/*
* Rotate the picture
* @param angle
* @param bitmap
* @return Bitmap
*/
Public static Bitmap rotaingImageView(int angle , Bitmap bitmap) {
//Rotate the image Action
Matrix matrix = new Matrix();;
matrix.postRotate(angle);
System.out.println("angle2=" + angle);
// Create a new image
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
Return resizedBitmap;
}
About Android in call system take pictures, return picture is rotated 90 degrees