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());
}
}
}
Aggregations