Search in sources :

Example 1 with QRCodeDecoder

use of jp.sourceforge.qrcode.QRCodeDecoder in project qrcode by yanbe.

the class J2MEImage method cameraCanvasCaptured.

void cameraCanvasCaptured(byte[] pngData) {
    cameraCanvas.stop();
    displayCanvas.setImage(pngData);
    Display.getDisplay(this).setCurrent(displayCanvas);
    Image image = Image.createImage(pngData, 0, pngData.length);
    // TODO Uncomment below for demo on emulator
    try {
        image = Image.createImage("/qrcode.jpg");
    } catch (IOException ioe) {
    }
    QRCodeDecoder decoder = new QRCodeDecoder();
    QRCodeDecoder.setCanvas(displayCanvas);
    try {
        decodedTextBox.setDecodedString(new String(decoder.decode(new J2MEImage(image))));
    } catch (DecodingFailedException dfe) {
        displayCanvas.println("Decoding failed");
        displayCanvas.println("(" + dfe.getMessage() + ")");
        displayCanvas.println("--------");
        return;
    }
    displayCanvas.println("--------");
    displayCanvas.addViewDecodedStringCommand();
}
Also used : IOException(java.io.IOException) QRCodeImage(jp.sourceforge.qrcode.data.QRCodeImage) Image(javax.microedition.lcdui.Image) QRCodeDecoder(jp.sourceforge.qrcode.QRCodeDecoder) DecodingFailedException(jp.sourceforge.qrcode.exception.DecodingFailedException)

Example 2 with QRCodeDecoder

use of jp.sourceforge.qrcode.QRCodeDecoder in project qrcode by yanbe.

the class JMFCanvas method run.

public void run() {
    for (; ; ) {
        FrameGrabbingControl fgc = (FrameGrabbingControl) processor.getControl("javax.media.control.FrameGrabbingControl");
        Buffer buf = fgc.grabFrame();
        BufferToImage btoi = new BufferToImage((VideoFormat) buf.getFormat());
        Image img = btoi.createImage(buf);
        QRCodeDecoder decoder = new QRCodeDecoder();
        int width = processor.getVisualComponent().getWidth();
        int height = processor.getVisualComponent().getHeight();
        canvas = new JMFCanvas();
        QRCodeDecoder.setCanvas(canvas);
        try {
            J2SEImage decoderImage = new J2SEImage(img, width, height);
            String decodedString = new String(decoder.decode(decoderImage));
            System.out.println("Result: " + decodedString);
            File resultImage = new File("C:\\tmp\\result.jpg");
            try {
                ImageIO.write(canvas.getImage(), "png", resultImage);
            } catch (IOException e) {
                System.out.println(e.getMessage());
            }
        } catch (DecodingFailedException e) {
            System.out.println("Error: " + e.getMessage());
        } catch (IllegalStateException e) {
            System.out.println("Error: " + e.getMessage());
        }
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            System.out.println(e.getMessage());
        }
    }
}
Also used : Buffer(javax.media.Buffer) IOException(java.io.IOException) FrameGrabbingControl(javax.media.control.FrameGrabbingControl) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) QRCodeImage(jp.sourceforge.qrcode.data.QRCodeImage) BufferToImage(javax.media.util.BufferToImage) BufferToImage(javax.media.util.BufferToImage) Point(jp.sourceforge.qrcode.geom.Point) File(java.io.File) QRCodeDecoder(jp.sourceforge.qrcode.QRCodeDecoder) DecodingFailedException(jp.sourceforge.qrcode.exception.DecodingFailedException)

Example 3 with QRCodeDecoder

use of jp.sourceforge.qrcode.QRCodeDecoder in project qrcode by yanbe.

the class J2SECanvas method main.

public static void main(String[] args) {
    if (args.length < 1) {
        System.err.println("Usage: QRCodeDecoderCUIExample imageFilePath");
        System.exit(1);
    }
    int numSuccesses = 0;
    int numFailures = 0;
    QRCodeDecoder decoder = new QRCodeDecoder();
    long start = System.currentTimeMillis();
    for (String filename : args) {
        if (processDecode(filename, decoder)) {
            System.err.print("[Success] ");
            numSuccesses++;
        } else {
            System.err.print("[Failure] ");
            numFailures++;
        }
        System.err.println(filename);
    }
    long processTime = System.currentTimeMillis() - start;
    System.err.println("Processed " + args.length + " images in " + processTime + "ms (" + processTime / args.length + " images/sec)");
    System.err.println("OK: " + numSuccesses + " NG: " + numFailures);
}
Also used : QRCodeDecoder(jp.sourceforge.qrcode.QRCodeDecoder)

Aggregations

QRCodeDecoder (jp.sourceforge.qrcode.QRCodeDecoder)3 IOException (java.io.IOException)2 QRCodeImage (jp.sourceforge.qrcode.data.QRCodeImage)2 DecodingFailedException (jp.sourceforge.qrcode.exception.DecodingFailedException)2 Image (java.awt.Image)1 BufferedImage (java.awt.image.BufferedImage)1 File (java.io.File)1 Buffer (javax.media.Buffer)1 FrameGrabbingControl (javax.media.control.FrameGrabbingControl)1 BufferToImage (javax.media.util.BufferToImage)1 Image (javax.microedition.lcdui.Image)1 Point (jp.sourceforge.qrcode.geom.Point)1