android通过zxing可识别bitmap多个二维码,具体使用如下
1.首先build文件添加依赖
implementation 'com.google.zxing:core:3.3.3'
2.使用 QRCodeMultiReader 来解析 Bitmap获取Result数组(二维码图片地址集合)
public static com.google.zxing.Result[] decodeQR(Bitmap srcBitmap) {
com.google.zxing.Result[] result = null;
if (srcBitmap != null) {
int width = srcBitmap.getWidth();
int height = srcBitmap.getHeight();
int[] pixels = new int[width * height];
srcBitmap.getPixels(pixels, 0, width, 0, 0, width, height);
// 新建一个RGBLuminanceSource对象
RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);
// 将图片转换成二进制图片
BinaryBitmap binaryBitmap = new BinaryBitmap(new
GlobalHistogramBinarizer(source));
QRCodeMultiReader reader = new QRCodeMultiReader();// 初始化解析对象
try {
result = reader.decodeMultiple(binaryBitmap,
CodeHintsUtils.getDefaultDecodeHints());// 解析获取一个Result数组
} catch (NotFoundException e) {
e.printStackTrace();
}
}
return result;
}
3.通过获取数组下的Result对象,result.getText();//得到二维码信息地址