A QR code is a two-dimensional barcode that can be used to store some useful data for identifying or tracking information. Sometimes you may need to create a QR code to embed information in the form of vertical and horizontal grids. Accordingly, this article explains how to create a QR Code programmatically in C#.
- C# API Installation to Generate QR Code
- Create QR Code in C#
- Generate QR Code with ForceQR Encoding in C#
C# API Installation to Generate QR Code
You need to install Aspose.BarCode for .NET API. It can be used to create or scan different kinds of barcodes. You may download the reference DLL file or install it with the following NuGet command.
PM> Install-Package Aspose.BarCode
Create QR Code in C#
You can create a QR Code by following the steps below:
- Initialize an instance of the BarcodeGenerator class while specifying the EncodeType and the input text.
- Set the version and encoding type for the QR Code.
- Generate a QR Code and save the output image in PNG format.
The code snippet below shows how to generate a QR Code in C#:
// Initialize an instance of BarcodeGenerator class | |
BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.QR, "Aspose"); | |
gen.Parameters.Barcode.XDimension.Pixels = 4; | |
// Set Auto version | |
gen.Parameters.Barcode.QR.QrVersion = QRVersion.Auto; | |
//Set ForceMicroQR QR encode type | |
gen.Parameters.Barcode.QR.QrEncodeType = QREncodeType.ForceMicroQR; | |
gen.Save(dataDir + "QREncodeTypeForceMicroQR.png", BarCodeImageFormat.Png); |
Generate QR Code with ForceQR Encoding in C#
Here you will learn how to create a ForceQR type of QR code in C#.
- Initialize an instance of the BarcodeGenerator class while specifying the EncodeType and the input text.
- Set the version and encoding type for the QR Code.
- Create a QR Code and write the generated QR code as a PNG image.
The following code example demonstrates how to generate a QR code with ForceQR encoding in C#:
// Initialize an instance of BarcodeGenerator class | |
BarcodeGenerator gen = new BarcodeGenerator(EncodeTypes.QR, "Aspose"); | |
gen.Parameters.Barcode.XDimension.Pixels = 4; | |
// Set Auto version | |
gen.Parameters.Barcode.QR.QrVersion = QRVersion.Auto; | |
//Set ForceQR QR encode type | |
gen.Parameters.Barcode.QR.QrEncodeType = QREncodeType.ForceQR; | |
gen.Save(dataDir + "QREncodeTypeForceQR.png", BarCodeImageFormat.Png); |
Get a Free License
You may request a free temporary license to evaluate the API to its full capacity.
Conclusion
In this article, you have learned how to generate a QR Code with different versions and encoding types programmatically in C#. Simply follow the steps and code snippet to create a QR Code in C#. Besides, may visit the documentation section to explore various other features offered by Aspose.BarCode for .NET API. In case of any questions, please feel free to write to us at forum.