2013-02-21 50 views
2

我使用zxing來解碼QR碼圖像,但它總是返回一個NotFoundException。在http://zxing.org/w/decode.jspx在線解碼器掃描這些圖像非常好,所以它應該能夠在我的應用程序中這樣做。 我使用此代碼:Android zxing NotFoundException

String path = Environment.getExternalStorageDirectory().getPath()+"/QRPictures/QRTest.bmp"; 
Bitmap bmp = BitmapFactory.decodeFile(path); 
int[] pixels = new int[bmp.getWidth()*bmp.getHeight()]; 
bmp.getPixels(pixels, 0, bmp.getWidth(), 0, 0, bmp.getWidth(), bmp.getHeight()); 
LuminanceSource source = new RGBLuminanceSource(bmp.getWidth(), bmp.getHeight(), pixels); 
BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source)); 
Reader reader = new MultiFormatReader(); 
try { 
    Result result = reader.decode(bitmap); 
    String contents = result.getText(); 
    Log.d(TAG, content); 
} catch (NotFoundException e) { 
    Log.d(TAG, "NFE"); 
} catch (ChecksumException e) { 
    Log.d(TAG, "CSE"); 
} catch (FormatException e) { 
    Log.d(TAG, "FE"); 
} 

你能幫忙嗎?

回答

1

根據an answer到一個相關的問題,使用TRY_HARDER解碼提示可能會有所幫助,因爲它「的準確性optmizes,而不是速度」:

Hashtable<DecodeHintType, Object> decodeHints = new Hashtable<DecodeHintType, Object>(); 
decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE); 
Result result = reader.decode(bitmap, decodeHints); 

如果相同的圖像在被正確地解釋在線服務,但在你的情況下失敗,很可能他們有TRY_HARDER,而你有它。

+1

我還是得到了NotFoundException,即使TRY_HARDER – user2093946 2013-02-21 12:08:09

1

我也有這個問題。我解決了它。 試試這個提示添加到您的代碼:

hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE); 
0

我解決了這個由:hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);

相關問題