gpt4 book ai didi

Android zxing NotFoundException

转载 作者:行者123 更新时间:2023-11-29 00:31:57 28 4
gpt4 key购买 nike

我正在使用 zxing 解码二维码图像,但它总是返回 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com