Determine QR code version and error correction level

May 29, 2014 at 12:48 PM
Hello there!

When encoding a QR code from some data it would be really useful to be able to determine what version and error correction level was used if no options have been specified. Even, there could be an exposed method that would simply return those from data passed in without actually generating the QR code...

Is that currently possible in any way? I couldn't find how.


Thanks!
Coordinator
May 29, 2014 at 2:52 PM
By default, if no other one is specified, the error correction level L is used.
You can receive some more details without rendering the QR code if you use the Encoder class.
QRCode qrCode = ZXing.QrCode.Internal.Encoder.encode("<your content here>", ErrorCorrectionLevel.L);
// use the result
... qrCode.Version ...
... qrCode.Mode ...
... qrCode.ECLevel ...
... qrCode.MaskPattern ...
... qrCode.Matrix ...
Marked as answer by ceottaki on 5/29/2014 at 7:44 AM
May 29, 2014 at 3:44 PM
Thanks, that's exactly what I needed.
Sep 12, 2016 at 4:57 PM
can you tell me how to switch to image it?
Coordinator
Sep 12, 2016 at 7:44 PM
Use the BarcodeWriter class.
Sep 13, 2016 at 3:45 AM
I can not encode the correct version.
            BarcodeWriter writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.QR_CODE;
            QRCode qrCode = ZXing.QrCode.Internal.Encoder.encode(content, ErrorCorrectionLevel.L);
            qrCode.Version = ZXing.QrCode.Internal.Version.getVersionForNumber(10);
            var barcode = writer.Write(qrCode.ToString());
            MemoryStream stream = new MemoryStream();
            stream.SetLength(0);
            barcode.Save(stream, System.Drawing.Imaging.ImageFormat.Png);
            var base64Data = Convert.ToBase64String(stream.ToArray());
            Image1.ImageUrl = "data:image/png;base64," + base64Data;
Coordinator
Sep 13, 2016 at 8:44 PM
As I said in another issue: you can't specify a specific version which should be used. The QR code encoder selects the version based on the content.
Sep 14, 2016 at 12:45 AM
thank you! Version Data Matrix section has likewise not.