Wednesday, 14 June 2017 07:27

Create a QR Code in C#

QR code (abbreviated from Quick Response Code) is a two dimensional (2D) barcode symbology first designed for the automotive industry in Japan. A QR code is readable from all directions and can use a variety of encoding modes such as numeric, alphanumeric and byte/binary to efficiently store data.

The following code example shows how to create a QR Barcode using Spire.Barcode.

Step 1: Instantiate a BarcodeSettings object.

BarcodeSettings settings = new BarcodeSettings();

Step 2: Set barcode type as QR code.

settings.Type = BarCodeType.QRCode;

Step 3: Set data and display text for the code.

settings.Data = "Hello 123456789";
settings.Data2D = "Hello 123456789";

Step 4: Set encode mode.

settings.QRCodeDataMode = QRCodeDataMode.AlphaNumber;

Step 5: Set width of the barcode bar module.

settings.X = 1.0f;

Step 6: Set error correction level of the barcode.

settings.QRCodeECL = QRCodeECL.H;

Step 7: Instantiate a BarCodeGenerator object.

BarCodeGenerator generator = new BarCodeGenerator(settings);

Step 8: Generate the barcode image.

Image image = generator.GenerateImage();

Step 9: Save the barcode image.

image.Save("QRCode.png");

The produced QR barcode image looks as follows.

Create a QR Code in C#

Full Code:

BarcodeSettings settings = new BarcodeSettings();
settings.Type = BarCodeType.QRCode;

settings.Data = "Hello 123456789";
settings.Data2D = "Hello 123456789";
settings.QRCodeDataMode = QRCodeDataMode.AlphaNumber;
settings.X = 1.0f;
settings.QRCodeECL = QRCodeECL.H;

BarCodeGenerator generator = new BarCodeGenerator(settings);
Image image = generator.GenerateImage();
image.Save("QRCode.png");

Additional Info

  • tutorial_title: