codebude / QRCoder

A pure C# Open Source QR Code implementation
MIT License
4.59k stars 1.09k forks source link

Unreabable QR Generation? #83

Closed Jrud closed 7 years ago

Jrud commented 7 years ago

differentqr

differentqroriginal

I created this QR barcode while testing given the code 044600016566 to encode. It produced the attached barcodes that my 2D barcode scanner won't read. I've generated numerous other barcodes with your DLL and they all read just fine except for this one. The only difference that I can see is that the bottom right reference marker doesn't have a solid black border around the white square.

Is this a failure of the QR code generator, a failure of my scanner for not being able to detect something that is standard, or a failure of my understanding of how they work?

codebude commented 7 years ago

Hi John, this doesn't look good. My scanner app isn't able to read this, too. Could please give more information on the encoding level used and the version of the QrCoder.dll?

Edit:// That "doesn't look good" means, that I'm not happy, that this code isn't working. Nevertheless, I think the "bug" doesn't come from the "reference pattern" you marked in the image. Because this "reference pattern", in the ISO normal called "aligment pattern", has to be set only from QR code version 2 or higher. The generated code in your example is 21x21 blocks, which is a QR code version 1 and has by definition no such alignment pattern. It's more like coincidence that there is a pattern, which looks like an alignment pattern.

codebude commented 7 years ago

Ok, I just generated your payload (044600016566) with all error levels and none of the QR codes looked like yours. Either you use an outdated version of the QrCoder or your input string wasn't "044600016566". ;-)

That's the code, which is generated for ECC Level "H", with the current library version: 2017-08-27 13_58_19-qrcoder

Jrud commented 7 years ago

Here is the code I wrote to :

public static Bitmap MakeQR(string Text) { Bitmap Result = null;

        using (QRCoder.QRCodeGenerator Generator = new QRCodeGenerator())
        {
            using (QRCodeData Data = Generator.CreateQrCode(Text, QRCodeGenerator.ECCLevel.H))
            {
                using (QRCoder.BitmapByteQRCode bbqc = new BitmapByteQRCode(Data))
                { 
                    byte[] graphic = bbqc.GetGraphic(4);

                    using (MemoryStream ms = new MemoryStream(graphic))
                    {
                         Result = new Bitmap(ms);
                    }
                }
            }
        }

        return Result;
    }

I am using DLL version 1.3.0.0

Are these incorrect?

codebude commented 7 years ago

Ok, you are using the BitmapByteQRCode. I re-checked, but I get the exact same image like shown in my screenshot before. You got the DLL 1.3.0.0 from checking out and compiling the current Github code? If so, we should have the exact same code. I really don't get it, why my QR code looks different from yours. a) Could you check the QR code result, when using the QRCoderDemo project/app from this Github repo? b) Can you re-check (maybe via breakpoint/debugger) what your string (to be encoded) looks like. The only explanation for the difference, I can think of, is that your payload string isn't "044600016566". c) Which platform target/framework do you use?

Jrud commented 7 years ago

Ah, you were right, this was never a problem with the QR generator, I was passing in an empty string into the function from a bug farther up the process, and generating a QR with a blank for text seems to be what produces the non functional barcode. Sorry to have annoyed you, my software should never need to create a blank barcode so this is not an issue for me haha.

Thanks for the awesome tool!

tilkinsc commented 7 years ago

Should QRCoder throw an error on an invalid input?

codebude commented 7 years ago

@Jrud - nice to hear, that you could solve your problems and thanks for the compliments. @Hydroque - I think it's not QRCoder's task to catch empty payloads. The QR standard (ISO18004) just talks about maximum payload length, but not about minimum length. I couldn't find any hint in the ISO docs, which says that there must be at least one char of payload. In addition to that, QR codes work also without payload and are still readable.

So why should I prohibit something which is compliant to the norm? In my opinion, if this (empty payloads) is unwanted, this should be handled by the application's (user-)input validation.

tilkinsc commented 7 years ago

Wasn't the point that the empty payload generated an invalid QR code though?

codebude commented 7 years ago

@Hydroque that's what @Jrud wrote, but not what he meant. He meant, that the QR code gave an unexpected result (=empty string). Technically the QR code was correct/working. (Just scan his example QR code and you'll see, that it can be read without problems.) And as I already explained, an empty QR code is valid by standard. So if one dosn't want his app to create empty QR coders that should be part of user input validation in GUI, not a part of library.