Search in sources :

Example 21 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project pancm_project by xuwujing.

the class QrCodeMaxTest method decode.

// qrcode 解码
static void decode(String file) {
    try {
        Result result = null;
        BufferedImage image = null;
        image = ImageIO.read(new File(file));
        LuminanceSource source = new BufferedImageLuminanceSource(image);
        BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
        result = new MultiFormatReader().decode(bitmap, hints);
        String rtn = result.getText();
        System.out.println(rtn);
        System.out.println(rtn.length());
    } catch (Exception ex) {
        System.out.println(ex.toString());
    }
}
Also used : Hashtable(java.util.Hashtable) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) CharacterCodingException(java.nio.charset.CharacterCodingException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) File(java.io.File)

Example 22 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project pancm_project by xuwujing.

the class QrCodeCreateUtil method readQrCode.

/**
 * 读二维码并输出携带的信息
 *
 * @param inputStream the input stream
 * @throws IOException the io exception
 */
public static void readQrCode(InputStream inputStream) throws IOException {
    // 从输入流中获取字符串信息
    BufferedImage image = ImageIO.read(inputStream);
    // 将图像转换为二进制位图源
    LuminanceSource source = new BufferedImageLuminanceSource(image);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeReader();
    Result result = null;
    try {
        result = reader.decode(bitmap);
    } catch (ReaderException e) {
        e.printStackTrace();
    }
    System.out.println(result.getText());
}
Also used : QRCodeReader(com.google.zxing.qrcode.QRCodeReader) LuminanceSource(com.google.zxing.LuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Example 23 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project camel by apache.

the class BarcodeDataFormat method readImage.

/**
     * Reads the message from a code.
     */
private String readImage(final Exchange exchange, final InputStream stream) throws Exception {
    final MultiFormatReader reader = new MultiFormatReader();
    final BufferedInputStream in = exchange.getContext().getTypeConverter().mandatoryConvertTo(BufferedInputStream.class, stream);
    final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(in))));
    final Result result = reader.decode(bitmap, readerHintMap);
    // write the found barcode format into the header
    exchange.getOut().setHeader(Barcode.BARCODE_FORMAT, result.getBarcodeFormat());
    return result.getText();
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) BufferedInputStream(java.io.BufferedInputStream) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) Result(com.google.zxing.Result)

Example 24 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project camel by apache.

the class BarcodeTestBase method checkFormat.

private void checkFormat(File file, BarcodeFormat format) throws IOException {
    Reader reader = new MultiFormatReader();
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(file))));
    Result result;
    try {
        result = reader.decode(bitmap);
    } catch (ReaderException ex) {
        throw new IOException(ex);
    }
    assertEquals(format, result.getBarcodeFormat());
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) ImageReader(javax.imageio.ImageReader) MultiFormatReader(com.google.zxing.MultiFormatReader) Reader(com.google.zxing.Reader) IOException(java.io.IOException) BinaryBitmap(com.google.zxing.BinaryBitmap) HybridBinarizer(com.google.zxing.common.HybridBinarizer) Result(com.google.zxing.Result) ReaderException(com.google.zxing.ReaderException)

Example 25 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource 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

BufferedImageLuminanceSource (com.google.zxing.client.j2se.BufferedImageLuminanceSource)51 HybridBinarizer (com.google.zxing.common.HybridBinarizer)51 BufferedImage (java.awt.image.BufferedImage)33 BinaryBitmap (com.google.zxing.BinaryBitmap)24 Result (com.google.zxing.Result)19 MultiFormatReader (com.google.zxing.MultiFormatReader)17 HashMap (java.util.HashMap)15 DecodeHintType (com.google.zxing.DecodeHintType)10 File (java.io.File)10 Hashtable (java.util.Hashtable)10 QRCodeReader (com.google.zxing.qrcode.QRCodeReader)9 LuminanceSource (com.google.zxing.LuminanceSource)8 IOException (java.io.IOException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 Binarizer (com.google.zxing.Binarizer)3 NotFoundException (com.google.zxing.NotFoundException)3 Reader (com.google.zxing.Reader)3 ReaderException (com.google.zxing.ReaderException)3 Map (java.util.Map)3 JSONObject (com.alibaba.fastjson.JSONObject)2