解决办法:
int degree = ImageUtil.readPictureDegree(imageUri.getPath()); Bitmap bmpOk = ImageUtil.rotateToDegrees(bmp, degree);
/** * 图片旋转 * @param tmpBitmap * @param degrees * @return */ public static Bitmap rotateToDegrees(Bitmap tmpBitmap, float degrees) { Matrix matrix = new Matrix(); matrix.reset(); matrix.setRotate(degrees); return tmpBitmap = Bitmap.createBitmap(tmpBitmap, 0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight(), matrix, true); } /** * 读取照片exif信息中的旋转角度 * @param path 照片路径 * @return角度 */ 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; }
bmpOK就是我们需要的没有旋转过的照片了。