我使用 zxing 来解码 QRcode 图像,但它总是返回 NotFoundException。在线解码器http://zxing.org/w/decode.jspx可以完美地扫描这些图像,因此它应该能够在我的应用程序中执行此操作。 我正在使用这段代码:
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");
}
请您帮忙解决一下吗?
最佳答案
根据an answer相关问题,使用 TRY_HARDER
解码提示可能会有所帮助,因为它“优化准确性,而不是速度”:
Hashtable<DecodeHintType, Object> decodeHints = new Hashtable<DecodeHintType, Object>();
decodeHints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
Result result = reader.decode(bitmap, decodeHints);
如果相同的图像在在线服务中得到了正确的解释,但在您的情况下却失败了,则很可能他们在您关闭时打开了TRY_HARDER
。
关于Android zxing NotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14994674/