使用zxing android 二维码解码图片 [英] QR code decoding images using zxing android

查看:62
本文介绍了使用zxing android 二维码解码图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 Android 上做一个简单的应用程序,如下所示:

I am doing a simple application on Android which is the following:

将二维码图像放入应用程序的 Drawable 文件中.通过一个ButtonClick,它应该被解码并显示结果(使用Zxing库).

Putting a QR code Image in the Drawable file of the application. By a ButtonClick, it should be decoded and Display the result (using Zxing library).

我在 Java 上做了相同的应用程序(解码当时使用 BufferedImageLuminanceSource 类).

I have made the same application on Java (the decoding was then using BufferedImageLuminanceSource class).

在我的 android 应用程序中,我使用了 RGBLuminanceSource 类,如下所示:

In my android application, I used the RGBLuminanceSource class as follows:

LuminanceSource source = new RGBLuminanceSource(width, height, pixels)BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));

我在这里面临的问题是:图像必须太小而无法被 android 应用程序解码(我不得不尝试多种尺寸才能最终得到一个解码 QR 码图像的尺寸).同时,在 Java 应用程序中使用 BufferedImageLuminanceSource 可以轻松解码相同的图像,无需调整大小.

The problem I am facing here is that: the image has to be too small to be decoded by the android application(and I had to try many sizes to finally got one where the QR code Image is decoded). Meanwhile the same images were decoded easily using the BufferedImageLuminanceSource in Java application without any need to be resized.

如何避免这种调整大小的问题?

What to do to avoid this resizing Problem?

推荐答案

为时已晚,但可以帮助他人,

Its too late but it can be help to others,

所以我们可以使用Zxing库从Bitmap中获取Qr code Info.

So we can get Qr code Info from Bitmap using Zxing library.

 Bitmap generatedQRCode;
    int width = generatedQRCode.getWidth();
    int height = generatedQRCode.getHeight();
    int[] pixels = new int[width * height];
    generatedQRCode.getPixels(pixels, 0, width, 0, 0, width, height);

    RGBLuminanceSource source = new RGBLuminanceSource(width, height, pixels);

    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(source));

    Reader reader = new MultiFormatReader();
    Result result = null;
    try {
        result = reader.decode(binaryBitmap);
    } catch (NotFoundException e) {
        e.printStackTrace();
    } catch (ChecksumException e) {
        e.printStackTrace();
    } catch (FormatException e) {
        e.printStackTrace();
    }
    String text = result.getText();
    textViewQRCode.setText(" CONTENT: " + text);

这篇关于使用zxing android 二维码解码图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆