Prerequisites

  • Visual Studio or Visual Studio Code already installed
  • Install the below package, i.e., “QRCoder” via NuGet package manager.
Install-Package QRCoder

Let’s Start

The “QRCoder” DLL helps to generate QR code with just four lines of code in C#.

4 Lines of Code Snippet

QRCodeGenerator qrGenerator = new QRCodeGenerator();

QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrText, QRCodeGenerator.ECCLevel.Q);
QRCode qrCode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrCode.GetGraphic(20);

Description of each line of code

Initialize the QR code generator class

Create an instance of the QRCodeGenerator class.

QRCodeGenerator qrGenerator = new QRCodeGenerator();

Create QR code data

The next step is to initialize QR code data using the CreateQrCode method, which takes two arguments, i.e., string text for encoding inside the QR code, and another case defines the error correction level, i.e., ECCLevel.

Here, four different levels L (7%), M (15%), Q (25%) and H (30%) are available, whereby the percentage represents the hidden portion of the QR-code until the error correction algorithm can’t recreate the original message encoded in the QR code.

QRCodeData qrCodeData = qrGenerator.CreateQrCode(qrText, QRCodeGenerator.ECCLevel.Q);

#qr-code #qrcodegenerator #programming #dotnet #dotnet-core #visual studio code

Generate QR Code in 4 Lines of Code
7.55 GEEK