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); //返回旋轉後的圖片