Android zxing NotFoundException

标签 android zxing

我使用 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/

相关文章:

java - 带有 ClickListener 的搜索栏到搜索到的 DetailActivity 不起作用

java - 导入模块后 list 合并失败

java - android fragment 内的 fragment

java - "com.google.zxing.client.android.CaptureActivity"未找到且无法解析

java - 从图像文件中扫描二维码

android - 如何像 Android Emulator Loader 一样制作动画(GLINT Effect over Text)

android - 合并两个 JSON 的更好方法

android zxing条码扫描获取绑定(bind)不匹配

android - 如何在android中为QR码添加标志

java - 使用 ZXing 检测(多个)二维码