Git Product home page Git Product logo

Comments (2)

codebude avatar codebude commented on August 24, 2024

How do you try to resize? I reckon you tried to create a normal QR Code via QRCode class and then resize the resulting Bitmap of the GetGraphic method.

In this case it's clear that you get bad quality graphics, because the you are working on a Bitmap which has image information pixel by pixel. When resizing the quality shrinks because you have information loss.

For now I can think of three solutions:

  1. When calling the GetGraphic method set the parameter "pixelsPerModule". This parameter tells the QRCoder how much pixels each black (or white) block should have on it's outer sides. So for example: The QR Code exists of 21 blocks. If you set pixelsPerModule to 10 the resulting QR Code will have a width of ~210 pixel.
  2. Use the SvgQRCode class instead of QRCode. It returns the QRCode in SVG format which is an vector format. (Vector graphics can be resized without quality loss.)
  3. Implement your own renderer. All QRCode types are implemented in the same manner. Just create a new class, ChenchiQRCode.cs for example, which inherits from AbstractQRCode. Then override the GetGraphic method and implement your own renderer. The module information (the white and black blocks) is stored in this.QrCodeData.ModuleMatrix which can be used in the overridden GetGraphics class.

Just let me know if this solved your problem. If you implemented your own QRCode type feel free to push it to this repository.

from qrcoder.

PEQSPC avatar PEQSPC commented on August 24, 2024

If I increase the dpi of the image and then resize the image, will it work?

Like this:

using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
                {
                    QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrText, QRCodeGenerator.ECCLevel.Q);
                    using (QRCode qrCode = new QRCode(qrCodeData))
                    {
                        Bitmap qrImage = qrCode.GetGraphic(2);
                        
                        qrImage.MakeTransparent(Color.Transparent);
                        Bitmap resizedImage = new Bitmap(qrImage, new Size(82, 82));
                        qrImage.SetResolution(400, 400);
                        string fileName = $"{Part_Number}_QTYTOTAL.png";
                        string filePath = Path.Combine(folderPath, fileName);
                        qrImage.Save(filePath, ImageFormat.Png);
                    }
                }

from qrcoder.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.