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