exifinterface获取图片属性并旋转
1、加入依赖
implementation 'com.android.support:exifinterface:27.1.1'
2、旋转代码
Matrix mat = new Matrix();
Bitmap bitmap = BitmapFactory.decodeFile(path, options);
ExifInterface ei = new ExifInterface(path);
int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL); //获取图片方向
switch (orientation) { //旋转
case ExifInterface.ORIENTATION_ROTATE_90:
mat.postRotate(90);
break;
case ExifInterface.ORIENTATION_ROTATE_180:
mat.postRotate(180);
break;
}
return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), mat, true); //返回旋转后的图片