use of com.google.zxing.Binarizer in project hutool by looly.
the class QrCodeUtil method decode.
/**
* 将二维码图片解码为文本
*
* @param image {@link Image} 二维码图片
* @return 解码后的文本
*/
public static String decode(Image image) {
final MultiFormatReader formatReader = new MultiFormatReader();
final LuminanceSource source = new BufferedImageLuminanceSource(ImageUtil.toBufferedImage(image));
final Binarizer binarizer = new HybridBinarizer(source);
final BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
final HashMap<DecodeHintType, Object> hints = new HashMap<>();
hints.put(DecodeHintType.CHARACTER_SET, CharsetUtil.UTF_8);
Result result;
try {
result = formatReader.decode(binaryBitmap, hints);
} catch (NotFoundException e) {
throw new QrCodeException(e);
}
return result.getText();
}
use of com.google.zxing.Binarizer in project portal by ixinportal.
the class parseQRCodeTool method parseQRCode.
public static String[] parseQRCode(InputStream imageInputStream) throws Exception {
BufferedImage image = ImageIO.read(imageInputStream);
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map<DecodeHintType, Object> hints = new HashMap<>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
MultiFormatReader formatReader = new MultiFormatReader();
Result result = formatReader.decode(binaryBitmap, hints);
String[] eInvoiceInfo = getEinvoiceInfo(result.getText());
return eInvoiceInfo;
}
use of com.google.zxing.Binarizer in project ngtesting-platform by aaronchen2k.
the class QrcodeServiceImpl method decode.
@Override
public JSONObject decode(String filePath) {
BufferedImage image;
try {
image = ImageIO.read(new File(filePath));
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map<DecodeHintType, Object> hints = new HashMap<DecodeHintType, Object>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
Result result = new MultiFormatReader().decode(binaryBitmap, hints);
System.out.println(result.getText());
JSONObject content = JSONObject.parseObject(result.getText());
System.out.println("encode: " + result.getBarcodeFormat());
return content;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.google.zxing.Binarizer in project portal by ixinportal.
the class parseQRCodeTool method parseQRCode.
/**
* 解析指定路径下的二维码图片
*
* @param filePath 二维码图片路径
* @return
*/
public static String[] parseQRCode(File PDFImageFile) throws Exception {
BufferedImage image = ImageIO.read(PDFImageFile);
LuminanceSource source = new BufferedImageLuminanceSource(image);
Binarizer binarizer = new HybridBinarizer(source);
BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
Map<DecodeHintType, Object> hints = new HashMap<>();
hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
MultiFormatReader formatReader = new MultiFormatReader();
Result result = formatReader.decode(binaryBitmap, hints);
String[] eInvoiceInfo = getEinvoiceInfo(result.getText());
return eInvoiceInfo;
}
Aggregations