无法解码二维码

发布于 2024-11-09 23:01:37 字数 807 浏览 3 评论 0原文

我已经尝试解码 QR 码很多天了,并且已经能够解码由免费应用程序和其他东西生成的 QR 码。问题是当我尝试使用从相机拍摄的图像时,可能会变得模糊,有额外的内容,以微小角度拍摄,我无法解码它们。

注意:我不想使用意图来调用现有的条形码阅读器。

 Bitmap bmap=BitmapFactory.decodeResource(getResources(),R.drawable.qrImage);


    LuminanceSource source = new RGBLuminanceSource(bmap);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeMultiReader();



    try{
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        Result result = reader.decode(bitmap, hints);



    TextView tv= (TextView) findViewById(R.id.tv1);
    tv.setText(result.getText());
    }catch(Exception e)
    {
        e.printStackTrace();
    }

I have been trying to decode the QR code for many days and have been able to decode the QR codes that are generated by the free applications and stuff.The problem is when i try to use the images taken from camera which can be blur,have extra content,captured at a slight angle, i cant decode them.

NOTE:I dont want to use the intent to call the existing barcode reader.

 Bitmap bmap=BitmapFactory.decodeResource(getResources(),R.drawable.qrImage);


    LuminanceSource source = new RGBLuminanceSource(bmap);
    BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));
    QRCodeReader reader = new QRCodeMultiReader();



    try{
        Hashtable<DecodeHintType, Object> hints = new Hashtable<DecodeHintType, Object>();
        hints.put(DecodeHintType.TRY_HARDER, Boolean.TRUE);
        Result result = reader.decode(bitmap, hints);



    TextView tv= (TextView) findViewById(R.id.tv1);
    tv.setText(result.getText());
    }catch(Exception e)
    {
        e.printStackTrace();
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗地喜欢 2024-11-16 23:01:37

您尝试过zxing二维码扫描仪吗?它是一种开源代码,可用于读取几乎所有类型的条形码。您可以从以下链接下载zxing的源代码:http://code.google.com /p/zxing/source/checkout 在此他们明确指定了如何扫描二维码。只需通过代码即可。我还可以建议另一个链接来帮助您运行源代码:http://www.falatic.com/index.php/12/building-zxing-for-android-part-3-using-eclipse 。之后探索代码你就可以整理出来了

Have you tried zxing QR code scanner. It is an open source code which is useful for reading almost all types of bar codes. you can download the source code of zxing from this link: http://code.google.com/p/zxing/source/checkout in this they have clearly specified the how to scan a qr code. Just go through the code. I can also suggest another link that will help you to run the source code: http://www.falatic.com/index.php/12/building-zxing-for-android-part-3-using-eclipse . After that explore the code you can sort it out

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文