2011-05-31 111 views
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(); 
} 

這工作現在,謝謝!

回答

0

該項目中有BUG的示例代碼,由BUG傢伙提供。請參閱bug/。雖然這已經很老了。

QRCoder是你的班級,不是嗎?所以我不知道這是BUG還是圖書館的問題。

+0

圖書館工作正常 - 我直接從Bug Labs的人。此刻我不使用相機,我正在將圖像直接導入到該功能中。 – saranicole 2011-05-31 18:03:29

+0

終於通過用自己的源代碼取代Reader來實現它的工作。不知道如何,但讀者從未寫入。 – saranicole 2011-05-31 19:53:48