Search in sources :

Example 31 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project DevKits by qmjy.

the class CodecFrame method run.

@Override
public void run() {
    do {
        try {
            Thread.sleep(100);
        } catch (InterruptedException e) {
            LOGGER.info("Sleep failed in recognize QR code...");
        }
        if (webcam != null) {
            BufferedImage image = null;
            if (webcam.isOpen()) {
                if ((image = webcam.getImage()) == null) {
                    continue;
                }
                LuminanceSource source = new BufferedImageLuminanceSource(image);
                BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
                try {
                    Result result = new MultiFormatReader().decode(bitmap);
                    if (result != null) {
                        DKSystemUtil.playSound(DKSystemUtil.SOUND_TYPE_SCAN);
                        String resultTxt = "<html>Recognized result as below has been set to the clipboard:<br/><span style='color:RED'>";
                        Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
                        Transferable tText = new StringSelection(result.getText());
                        clip.setContents(tText, null);
                        JOptionPane.showMessageDialog(this, resultTxt + result.getText() + "</span></html>", "QR Recognize Result", JOptionPane.INFORMATION_MESSAGE);
                    }
                } catch (NotFoundException e) {
                    LOGGER.info("Recognize QR Code from camera...");
                }
            }
        }
    } while (true);
}
Also used : Transferable(java.awt.datatransfer.Transferable) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) StringSelection(java.awt.datatransfer.StringSelection) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) Clipboard(java.awt.datatransfer.Clipboard)

Example 32 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project mica by lets-mica.

the class QrCode method read.

/**
 * 从指定的 QRCode 图像对象中解析出其内容。
 *
 * @param qrCodeImage QRCode 图像对象
 * @param hints hints
 * @return QRCode 中的内容
 */
public static String read(BufferedImage qrCodeImage, Map<DecodeHintType, ?> hints) {
    LuminanceSource source = new BufferedImageLuminanceSource(qrCodeImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    try {
        Result result = new QRCodeReader().decode(bitmap, hints);
        return result.getText();
    } catch (NotFoundException | ChecksumException | FormatException e) {
        throw Exceptions.unchecked(e);
    } finally {
        qrCodeImage.getGraphics().dispose();
    }
}
Also used : QRCodeReader(com.google.zxing.qrcode.QRCodeReader) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) HybridBinarizer(com.google.zxing.common.HybridBinarizer)

Example 33 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project vividus by vividus-framework.

the class BarcodeActions method scanBarcode.

public String scanBarcode(BufferedImage barcode) throws NotFoundException {
    LuminanceSource source = new BufferedImageLuminanceSource(barcode);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    Result result = new MultiFormatReader().decode(bitmap);
    return result.getText();
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) 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) Result(com.google.zxing.Result)

Example 34 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project java-learning by HouariZegai.

the class QRCodeReader method decodeQRCode.

private static String decodeQRCode(File qrCodeimage) {
    BufferedImage bufferedImage = null;
    try {
        bufferedImage = ImageIO.read(qrCodeimage);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }
    LuminanceSource source = new BufferedImageLuminanceSource(bufferedImage);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    try {
        Result result = new MultiFormatReader().decode(bitmap);
        return result.getText();
    } catch (NotFoundException nfe) {
        System.out.println("There is no QR code in the image!");
        return null;
    }
}
Also used : BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) IOException(java.io.IOException) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage)

Example 35 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project -- by 981011512.

the class QRCodeUtils method getContentFromQRCode.

public String getContentFromQRCode(String filePath) {
    MultiFormatReader formatReader = new MultiFormatReader();
    File file = new File(filePath);
    BufferedImage image;
    try {
        image = ImageIO.read(file);
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
        HashMap hints = new HashMap();
        // 指定字符编码为“utf-8”
        hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
        Result result = formatReader.decode(binaryBitmap, hints);
        return result.toString();
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) HashMap(java.util.HashMap) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) File(java.io.File) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result)

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