1获取图片地址路径
Screen Shot 2020-03-09 at 11.46.36.png
2识别
public Result scanningImage(Uri uri) {
if (uri == null) {
return null;
}
Hashtable<DecodeHintType, String> hints = new Hashtable<>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF8"); //设置二维码内容的编码
Bitmap bitmap = BitmapUtil.decodeUri(this, uri, 500, 500);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 50, baos);
int width = bitmap.getWidth();
int height = bitmap.getHeight();
int[] pix = new int[width * height];
bitmap.getPixels(pix, 0, width, 0, 0, width, height);
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pix);
BinaryBitmap bitmap1 = new BinaryBitmap(new HybridBinarizer(source));
QRCodeReader reader = new QRCodeReader();
try {
return reader.decode(bitmap1, hints);
} catch (NotFoundException e) {
e.printStackTrace();
} catch (ChecksumException e) {
e.printStackTrace();
} catch (FormatException e) {
e.printStackTrace();
}
return null;
}
网友评论