Search in sources :

Example 41 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project SeleniumTestNGParallel by anhtester.

the class TestQRCode method QRCode.

@Test
public void QRCode() throws NotFoundException, IOException {
    driver.get("http://qrcode.meetheed.com/qrcode_examples.php");
    driver.manage().window().maximize();
    String qrCodeURL = driver.findElement(By.xpath("//img[@src='images/qr_code_con.png']")).getAttribute("src");
    // Create an object of URL Class
    URL url = new URL(qrCodeURL);
    // Pass the URL class object to store the file as image
    BufferedImage bufferedimage = ImageIO.read(url);
    // Process the image
    LuminanceSource luminanceSource = new BufferedImageLuminanceSource(bufferedimage);
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(luminanceSource));
    // To Capture details of QR code
    Result result = new MultiFormatReader().decode(binaryBitmap);
    System.out.println(result.getText());
}
Also used : BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) HybridBinarizer(com.google.zxing.common.HybridBinarizer) URL(java.net.URL) BufferedImage(java.awt.image.BufferedImage) BaseTest(anhtester.com.common.BaseTest) Test(org.testng.annotations.Test)

Example 42 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project bh3login by Yarukon.

the class Main method doScan.

public static void doScan() {
    try {
        // 登录结果, 解析自个写就行
        JsonObject result = (JsonObject) JsonParser.parseString(FileUtils.readFileToString(new File("E:/BH3BiliLogin/result.json"), "UTF-8"));
        QRScanner scanner = new QRScanner(result.get("uid").getAsString(), result.get("access_key").getAsString());
        // 全屏截图找二维码 所以确保没别的二维码在桌面上
        Robot robot = new Robot();
        Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
        System.out.println("屏幕大小: " + d);
        MultiFormatReader multiFormatReader = new MultiFormatReader();
        LuminanceSource source = new BufferedImageLuminanceSource(robot.createScreenCapture(new Rectangle(d)));
        Binarizer binarizer = new HybridBinarizer(source);
        BinaryBitmap binaryBitmap = new BinaryBitmap(binarizer);
        Map hints = new HashMap();
        hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
        hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");
        Result scanResult = multiFormatReader.decode(binaryBitmap, hints);
        // 解析URL并登入
        HashMap<String, String> shit = Utils.stripUrl(URLDecoder.decode(scanResult.getText(), "UTF-8"));
        scanner.bizKey = shit.get("biz_key");
        scanner.ticket = shit.get("ticket");
        scanner.appID = shit.get("app_id");
        scanner.doQRLogin();
    } catch (Exception ex) {
        // 错误抛出
        System.out.println("如果错误为com.google.zxing.NotFoundException代表未找到二维码");
        ex.printStackTrace();
    }
}
Also used : HashMap(java.util.HashMap) JsonObject(com.google.gson.JsonObject) Dimension(java.awt.Dimension) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) File(java.io.File) HybridBinarizer(com.google.zxing.common.HybridBinarizer) HashMap(java.util.HashMap) Map(java.util.Map)

Example 43 with BufferedImageLuminanceSource

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

the class CameraLatencyTest method paint.

@Override
public void paint(Graphics g) {
    BufferedImage image = this.image;
    // TODO only send the QR code 4x a second or so instead of on every frame to reduce
    // load
    long time = System.currentTimeMillis();
    try {
        long t = System.currentTimeMillis();
        Map hintMap = new HashMap();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
        Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap, hintMap);
        latency = time - Long.parseLong(qrCodeResult.getText());
        System.arraycopy(latencies, 1, latencies, 0, latencies.length - 1);
        latencies[latencies.length - 1] = latency;
        averageLatency = 0;
        for (int i = 0; i < latencies.length; i++) {
            averageLatency += latencies[i];
        }
        averageLatency /= latencies.length;
        flashCount = 6;
    } catch (Exception e) {
    }
    g.setColor(Color.black);
    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(Color.white);
    g.drawImage(image, 0, 0, null);
    g.drawString("Time: " + (System.currentTimeMillis() - t), 10, 40);
    g.drawString("FPS: " + fps, 10, 60);
    if (flashCount-- > 0) {
        g.setColor(Color.green);
    }
    g.drawString("Latency: " + latency, 10, 80);
    g.drawString(String.format("Average Latency: %.2f", averageLatency), 10, 100);
    try {
        Map hintMap = new HashMap();
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);
        BitMatrix matrix = new MultiFormatWriter().encode("" + System.currentTimeMillis(), BarcodeFormat.QR_CODE, 64, 64, hintMap);
        BufferedImage qrCode = MatrixToImageWriter.toBufferedImage(matrix);
        g.drawImage(qrCode, 20, 120, null);
    } catch (Exception e) {
    }
}
Also used : MultiFormatReader(com.google.zxing.MultiFormatReader) HashMap(java.util.HashMap) BitMatrix(com.google.zxing.common.BitMatrix) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) Result(com.google.zxing.Result) MultiFormatWriter(com.google.zxing.MultiFormatWriter) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BinaryBitmap(com.google.zxing.BinaryBitmap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 44 with BufferedImageLuminanceSource

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

the class QrCodeKit method decode.

/**
 * @param srcImgFilePath 要解码的图片地址
 * @return {Result}
 */
public static Result decode(String srcImgFilePath) {
    Result result = null;
    BufferedImage image;
    try {
        File srcFile = new File(srcImgFilePath);
        image = ImageIO.read(srcFile);
        if (null != image) {
            LuminanceSource source = new BufferedImageLuminanceSource(image);
            BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
            Hashtable<DecodeHintType, String> hints = new Hashtable<DecodeHintType, String>();
            hints.put(DecodeHintType.CHARACTER_SET, "UTF-8");
            result = new MultiFormatReader().decode(bitmap, hints);
        } else {
            throw new IllegalArgumentException("Could not decode image.");
        }
    } catch (Exception e) {
        log.error("图片解码错误", e);
    }
    return result;
}
Also used : Hashtable(java.util.Hashtable) HybridBinarizer(com.google.zxing.common.HybridBinarizer) BufferedImage(java.awt.image.BufferedImage) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) File(java.io.File)

Example 45 with BufferedImageLuminanceSource

use of com.google.zxing.client.j2se.BufferedImageLuminanceSource in project spring-commons by damianwajser.

the class DefaultFormatter method read.

public String read(byte[] qr) throws NotFoundException, IOException {
    InputStream qrBytes = new ByteArrayInputStream(qr);
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(ImageIO.read(qrBytes))));
    Result result = new MultiFormatReader().decode(binaryBitmap);
    return result.getText();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) BufferedImageLuminanceSource(com.google.zxing.client.j2se.BufferedImageLuminanceSource) 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