QR code generated by android zxing library does not scan with most QR scanners

I am posting this to answer my own question (to spread this word in case anyone else had this problem.)

I am creating a QR code using Android ZXing library. The QR code is generated correctly and I can display it (after manually rendering it with QRCode.getMatrix().getArray()

.) However, the generated QR code does not scan most of the QR code readers available in the Android market, including the ZXing scanner itself

Also, whenever I set the error correction level to Encoder

, it ignores it and encodes some random level (usually the Q level).

I am generating QR code using this piece of code:

    QRCode code;

    try
    {
            code = Encoder.encode ("... QRCODEDATA ...", ErrorCorrectionLevel.L);
    }
    catch (WriterException ex)
    {
            log ("Failed to obtain a QR code");
            return null;
    }
    

... and then, after receiving the object QRCode

, I draw the bitmap like so:

byte[][] bitArray = qrCode.getMatrix().getArray();

        if(bitArray == null || bitArray.length < 1)
            return null;

        for(int x = 0;x < bitArray.length;x++)
        {
            for(int y = 0;y < bitArray[x].length;y++)
            {
                if(bitArray[x][y] == 0)
                    bitmapDrawCell(x,y,WHITE);
                else
                    bitmapDrawCell(x,y,BLACK);
            }
        }

      

code>

This is where I end.


It looks correct, but it won't scan. Several QR code scanners will scan it anyway, but most won't. What's happening?

+3


source to share


2 answers


The answer to this question is:

The QR code is actually reversed. Although the ZXing documentation does not explain how to index the array that qrCode.getMatrix () returns by getArray (), it assumes that you index it as [y] [x] and then draw that cell at point (x, y). The code posted in the question indexes the array as [x] [y], which flips the image along the Y = X line.

The resulting QR code seems legitimate, but only smart scanners can detect this kind of flipping and scan it.



The error correction level bits are also in the opposite corner, so if you had to check manually (looking at a few bits in the lower right corner of the image), then it turns out that the library ignores the adjustment error correction.

flipped QR code

+3


source


Not necessarily the answer to your question, but you might consider a QR QR generator. I've used it and it's pretty simple. Google QR



+2


source







All Articles