3
我还没有用ZXing解码QR码。我正在使用来自buglabs.net的BUG,但问题似乎与硬件没有任何关系,而是图像的格式。让ZXing Reader解码位图
这是我到目前为止有:
try {
LuminanceSource source = new AWTImageLuminanceSource(bimage);
bitmap = new BinaryBitmap(new GlobalHistogramBinarizer(source));
Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
Result result = reader.decode(bitmap, hints) ;
System.out.println("result is:" + result.getText());
} catch (ReaderException re) {
System.out.println("I can't find a barcode here");
}
码处断裂reader.decode(位图,提示)。我得到一个NullPointerException以下跟踪:
java.lang.NullPointerException
at qrcoder.QRCoder.shoot(QRCoder.java:152) // this is the camera shoot function
at qrcoder.QRCoder.buttonEvent(QRCoder.java:89) // press button
at com.buglabs.bug.input.pub.InputEventProvider.run(InputEventProvider.java:90)
不知道什么InputEventProvider试图告诉我。
非常感谢, 萨拉
不知道怎么样,但是读者从未得到写入。最后,将读者自己的源代码替换回函数,直接使用解码器。
private void shoot() throws IOException, NotFoundException, FormatException, ChecksumException {
// take the picture
Hashtable hints = null;
DecoderResult decoderResult;
cameraLED.setLEDFlash(true);
camera.grabPreview(buf);
camera.grabPreview(buf);
cameraLED.setLEDFlash(false);
InputStream in = new ByteArrayInputStream(camera.grabFull());
BufferedImage bImageFromConvert = ImageIO.read(in);
LuminanceSource source = new BufferedImageLuminanceSource(bImageFromConvert);
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
ResultPoint[] points;
final Decoder decoder = new Decoder();
DetectorResult detectorResult = new Detector(bitmap.getBlackMatrix()).detect(hints);
decoderResult = decoder.decode(detectorResult.getBits(), hints);
points = detectorResult.getPoints();
Result result = new Result(decoderResult.getText(), decoderResult.getRawBytes(), points, BarcodeFormat.QR_CODE);
if (result.getText() != null){
System.out.println("result is:" + result.getText());
}
else {System.out.println("bitmap is null");}
ic.repaint();
}
这工作现在,谢谢!
图书馆工作正常 - 我直接从Bug Labs的人。此刻我不使用相机,我正在将图像直接导入到该功能中。 – saranicole 2011-05-31 18:03:29
终于通过用自己的源代码取代Reader来实现它的工作。不知道如何,但读者从未写入。 – saranicole 2011-05-31 19:53:48