Android调用系统相机拍照后获取照片被旋转了90度的解决方法
解决办法:
(得到的bmpOk就是正常的图片)
int degree = ImageUtil.readPictureDegree(imageUri.getPath());
Bitmap bmpOk = ImageUtil.rotateToDegrees(bmp, degree);
/**
* 读取照片exif信息中的旋转角度
*
* @param path
* 照片路径
* @return角度
*/
public 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;
}
/**
* 图片旋转
*
* @param tmpBitmap
* @param degrees
* @return
*/
public 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);
}