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); //返回旋转后的图片
本文介绍如何使用EXIFInterface库来获取图片的方向属性,并通过Matrix类实现图片的自动旋转,确保图片显示正确。代码示例展示了如何加载图片,读取EXIF数据,判断旋转角度并进行旋转。
1639

被折叠的 条评论
为什么被折叠?



