codebude / QRCoder

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

want to generate SVG file of 2.5cm which contain 2600Bytes of data to SCAN in QR any suggestion #518

Closed lalwanikamaldev closed 2 months ago

lalwanikamaldev commented 2 months ago

Type of issue

[ ] Question (e.g. about handling/usage)

Expected Behavior

Current Behavior

Possible Solution (optional)

Steps to Reproduce (for bugs)

Your Environment

Shane32 commented 2 months ago

Versions (sizes) 38, 39, and 40 of QR codes support more than 2,600 bytes of content when using the low (L) ECC level. A "version 38" QR code has 169x169 modules. If you create a SVG, you can scale it to any size desired. However, for a 2.5cm QR code, each module would be approximately 0.15mm wide. It is quite unlikely that you could successfully scan such a large QR code printed so small with a typical handheld device. In fact, as this translates to 171dpi, it would be difficult to print/display this QR code accurately in the first place. But it is possible to do so.

Ref: https://www.qrcode.com/en/about/version.html

Shane32 commented 2 months ago

Sample code:


using QRCoder;
using System;
using System.IO;

class Program
{
    static void Main()
    {
        // Example content with 2600 characters (this will need to be replaced by your actual content)
        string content = new string('a', 2600); // Replace this with your desired content

        // Initialize the QR code generator with low error correction level to accommodate a large amount of data
        QRCodeGenerator qrGenerator = new QRCodeGenerator();
        QRCodeData qrCode = qrGenerator.CreateQrCode(content, QRCodeGenerator.ECCLevel.L);

        // Generate the QR code as an SVG
        SvgQRCode svgQrCode = new SvgQRCode(qrCode);
        string svgString = svgQrCode.GetGraphic(1);

        // Save to a file or use the string as needed
        File.WriteAllText("qr_code.svg", svgString);

        Console.WriteLine("QR Code generated and saved as SVG.");
    }
}
codebude commented 2 months ago

As @Shane32 has already correctly pointed out: It is technically possible to encode ~2600 bytes in a QR code and save it as SVG. However, this becomes illegibly small with a display size of 2.5cm x 2.5cm.

I think here you will either have to distribute your user data over several codes or you store the data e.g. on a server and encode only the url to the data in a QR code.

I hope this answers your question. Let us know if there are any further questions or if we can close the issue.

lalwanikamaldev commented 2 months ago

Thank you @Shane32 for C# code sample , now i am able to generate the QR code but my reader is not able to read it . how can i build a reader which can read this small data ? As you mentioned it is too small to read .

@codebude i want qr contain all data offline .

codebude commented 2 months ago

A reader can read it if the image provided has enough details. I guess your reader uses a camera? In that case you must upgrade your hardware/camera to capture the image of the QR code with enough details. Every block must be clearly visibile in the image captured that you pass to your reader.