Я еще не смог расшифровать QR-код с помощью ZXing. Я использую ошибку от buglabs.net, но проблема, похоже, не связана с оборудованием, а скорее с форматом изображения.
Это то, что я имею до сих пор:
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 пытается мне сказать.
Большое спасибо,
Sara
Не знаю, как, но Ридер никогда не писал. Наконец, работает путем подстановки собственного исходного кода Reader обратно в функцию, используя вместо этого непосредственно Decoder.
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();
}
Пока это работает, спасибо!