首先获取图片被旋转的角度
public static int readPictureDegree(String imagePath) {
int imageDegree = 0;
try {
ExifInterface exifInterface = new ExifInterface(imagePath);
int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90:
imageDegree = 90;
break;
case ExifInterface.ORIENTATION_ROTATE_180:
imageDegree = 180;
break;
case ExifInterface.ORIENTATION_ROTATE_270:
imageDegree = 270;
break;
}
} catch (IOException e) {
e.printStackTrace();
}
return imageDegree;
}
然后将图片旋转回去
public static Bitmap rotaingImageView(int angle, Bitmap mBitmap) {
Matrix matrix = new Matrix();
matrix.postRotate(angle);
Bitmap b = Bitmap.createBitmap(mBitmap, 0, 0, mBitmap.getWidth(), mBitmap.getHeight(), matrix, true);
if (b != null && b != mBitmap) {
mBitmap.recycle();
b = mBitmap;
}
return mBitmap;
}