Reputation: 21
I'm using zxing to decode QRcode images, but it always returns a NotFoundException. The online decoder at http://zxing.org/w/decode.jspx scans these images perfectly fine, so it should be able to do so in my app. I'm using this code :
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");
}
Could you help with this please ?
Upvotes: 2
Views: 3720
Reputation: 35
I solved this by: hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
Upvotes: 0
Reputation: 34
I had this problem too. And I solved it. Try add this hint to your code:
hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);
Upvotes: 1
Reputation: 22007
According to an answer to a related question, using the TRY_HARDER
decode hint might help, since it "optmizes for accuracy, not speed":
Hashtable<DecodeHintType, Object> decodeHints = new Hashtable<DecodeHintType, Object>();
decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
Result result = reader.decode(bitmap, decodeHints);
If the same image is being correctly interpreted in the online service but failing in your case, it's probable that they have TRY_HARDER
on while you have it off.
Upvotes: 1