3

ZXing で QR コードをデコードできませんでした。私は 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 にメールが届くことはありませんでした。最後に、代わりに Decoder を直接使用して、Reader 自身のソース コードを関数に戻すことで機能します。

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 に答える