QRCoder icon indicating copy to clipboard operation
QRCoder copied to clipboard

Improve QRCode output sharpness

Open DanielHolland opened this issue 3 years ago • 1 comments

Hi there,

[ ] Bug
[X] Question (e.g. about handling/usage)
[ ] Request for new feature/improvement

I am looking at using this package in place of calling Google's Chart API to generate QRCodes, the implementation I've followed uses the basic example in Wiki. What I see is that the image output of the library is noticeably blurred / pixelated when compared to the output from Google Chart.

Screenshot 2022-06-01 at 12 00 19

What can I do to improve on the image sharpness?

var url = "https://github.com/codebude/QRCoder/issues/new";
QRCodeGenerator _qrCode = new QRCodeGenerator();
QRCodeData _qrCodeData = _qrCode.CreateQrCode(url, QRCodeGenerator.ECCLevel.L);
PngByteQRCode qrCode = new PngByteQRCode(_qrCodeData);
byte[] qrAsPngByteArray = qrCode.GetGraphic(20);
using(var ms = new MemoryStream(qrAsPngByteArray))
{
    testQRCode.Image = new Bitmap(ms);
}
  • Version used: 1.4.3
  • Compiled from source or NuGet package?: Nuget
  • Payload/Encoded text: "https://github.com/codebude/QRCoder/issues/new"
  • Used payload generator: QRCodeGenerator
  • Used ECC-level: L
  • Used renderer class: PngByteQRCode
  • Environment (.NET 3.5, .NET 4.X, .NETCore, ...): .NET 4.7.2

DanielHolland avatar Jun 01 '22 10:06 DanielHolland

@DanielHolland
Official responses from the maintainer:

  • https://github.com/codebude/QRCoder/issues/152#issuecomment-437800025
  • https://github.com/codebude/QRCoder/issues/152#issuecomment-438461685
  • https://github.com/codebude/QRCoder/issues/299#issuecomment-910415076

I believe you want to raise the pixelsPerModule value in this line: byte[] qrAsPngByteArray = qrCode.GetGraphic(20);

Source from the Wiki

Parameter name Type Default Description
pixelsPerModule int   The pixel size each b/w module is drawn
It will make the file size larger but will sharpen the image.

Alternative

SvgQRCode This one is vector based so it can be resized without loss of quality but it may not fit your requirements.

digitaldirk avatar Jun 03 '22 20:06 digitaldirk

Hi @DanielHolland the solution to your problem was perfectly summarized by @digitaldirk thus I'm closing the issue. In case you have any further questions just reopen the issue. :-)

codebude avatar Apr 23 '24 22:04 codebude