3

我还不能用 ZXing 解码二维码。我正在使用来自 buglabs.net 的 BUG,但问题似乎与硬件无关,而与图像格式有关。

这是我到目前为止所拥有的:

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(bitmap, hints) 处中断。我收到带有以下跟踪的 ​​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 试图告诉我什么。

非常感谢,萨拉

不知道如何,但 Reader 从未被写入。最后,将 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();
}

这暂时有效,谢谢!

4

1 回答 1

0

项目中有BUG的示例代码,由BUG大佬提供。见bug/。不过它已经很老了。

QRCoder是你的课,不是吗?所以我不知道这是BUG还是图书馆的问题。

于 2011-05-31T17:39:54.193 回答