/**
* zxing解码二维码图片
* @param bitmap
* @return
* @throws NotFoundException
* @throws IOException
*/
private String zxingScanQrcodePicture(Bitmap bitmap) throws NotFoundException, IOException{
Map<DecodeHintType,Object> hints = new EnumMap<DecodeHintType,Object>(DecodeHintType.class);
Collection<BarcodeFormat> decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
decodeFormats.addAll(EnumSet.of(BarcodeFormat.QR_CODE));
hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
int lWidth = bitmap.getWidth();
int lHeight = bitmap.getHeight();
int[] lPixels = new int[lWidth * lHeight];
bitmap.getPixels(lPixels, 0, lWidth, 0, 0, lWidth, lHeight);
BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new RGBLuminanceSource(lWidth, lHeight, lPixels)));
Result lResult = new MultiFormatReader().decode(binaryBitmap, hints);
return lResult.getText();
}
zxing解码二维码图片
最新推荐文章于 2022-01-24 16:54:38 发布