QR code decoding images using zxing android

吃可爱长大的小学妹 提交于 2019-12-07 18:46:15

问题


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

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).

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

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));

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?


回答1:


Its too late but it can be help to others,

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);


来源:https://stackoverflow.com/questions/32120988/qr-code-decoding-images-using-zxing-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!