Search in sources :

Example 1 with Buffer

use of javax.media.Buffer 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)

Aggregations

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