【问题标题】:Android zxing NotFoundExceptionAndroid zxing NotFoundException
【发布时间】:2013-02-21 04:41:26
【问题描述】:

我正在使用 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");
} 

你能帮忙吗?

【问题讨论】:

    标签: android zxing


    【解决方案1】:

    根据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

    【讨论】:

    • 我仍然得到 NotFoundException,即使使用 TRY_HARDER
    【解决方案2】:

    我也有这个问题。我解决了它。 尝试将此提示添加到您的代码中:

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

    【讨论】:

      【解决方案3】:

      我通过以下方式解决了这个问题:hints.put(DecodeHintType.PURE_BARCODE, Boolean.TRUE);

      【讨论】:

        猜你喜欢
        • 2015-12-07
        • 2016-02-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多