-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
在使用analyzeBitmap方法解析图片时,可以加入图片旋转角度的判断,从而使解析的bitmap不被旋转导致条形码解析报错
public static int readPictureDegree(String imageFilePath) {
int degree = 0;
try {
ExifInterface exifInterface = new ExifInterface(imageFilePath);
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;
}
Matrix matrix = new Matrix();
matrix.reset();
matrix.setRotate(readPictureDegree(imageFilePath));
bmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), matrix, true);