Search in sources :

Example 1 with Binarizer

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();
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) DecodeHintType(com.google.zxing.DecodeHintType) HashMap(java.util.HashMap) NotFoundException(com.google.zxing.NotFoundException) HybridBinarizer(com.google.zxing.common.HybridBinarizer) Result(com.google.zxing.Result) LuminanceSource(com.google.zxing.LuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) Binarizer(com.google.zxing.Binarizer) HybridBinarizer(com.google.zxing.common.HybridBinarizer)

Example 2 with Binarizer

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;
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) DecodeHintType(com.google.zxing.DecodeHintType) HashMap(java.util.HashMap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) LuminanceSource(com.google.zxing.LuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) Binarizer(com.google.zxing.Binarizer) HybridBinarizer(com.google.zxing.common.HybridBinarizer)

Example 3 with Binarizer

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;
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) DecodeHintType(com.google.zxing.DecodeHintType) HashMap(java.util.HashMap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) JSONObject(com.alibaba.fastjson.JSONObject) LuminanceSource(com.google.zxing.LuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) JSONObject(com.alibaba.fastjson.JSONObject) BinaryBitmap(com.google.zxing.BinaryBitmap) File(java.io.File) Binarizer(com.google.zxing.Binarizer) HybridBinarizer(com.google.zxing.common.HybridBinarizer)

Example 4 with Binarizer

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;
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) DecodeHintType(com.google.zxing.DecodeHintType) HashMap(java.util.HashMap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) LuminanceSource(com.google.zxing.LuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) Binarizer(com.google.zxing.Binarizer) HybridBinarizer(com.google.zxing.common.HybridBinarizer)

Aggregations

Binarizer (com.google.zxing.Binarizer)4 BinaryBitmap (com.google.zxing.BinaryBitmap)4 DecodeHintType (com.google.zxing.DecodeHintType)4 LuminanceSource (com.google.zxing.LuminanceSource)4 MultiFormatReader (com.google.zxing.MultiFormatReader)4 Result (com.google.zxing.Result)4 HybridBinarizer (com.google.zxing.common.HybridBinarizer)4 HashMap (java.util.HashMap)4 BufferedImageLuminanceSource (com.google.zxing.client.j2se.BufferedImageLuminanceSource)3 BufferedImage (java.awt.image.BufferedImage)3 JSONObject (com.alibaba.fastjson.JSONObject)1 NotFoundException (com.google.zxing.NotFoundException)1 File (java.io.File)1