Using C# QR Code Generator Library: how to generate, create QR Code 2d barcode in asp.net, windows application with free c# open source example
- Easy integrated into .NET applications to generate QR Code with C#.NET class library
- Print valid matrix barcode QR Code images in ASP.NET websites and WinForms applications
- Support integrating 2D barcodes QR Code, Data Matrix & PDF-417 in Crystal Reports and RDLC Reports
- Draw and save QR Code bar codes in gif, jpeg, png, tiff, and bitmap formats with C#.NET programming
- Multiple properties for selection, such as QR Code version, data mode, ECL, Structure Append, etc
- A variety of barcode options are user-defined, including module width, height, resolution, orientation, etc
C# QR Code Barcode Generator Overview
Barcode Generator for .NET Suite is an easy-to-use barcode encoder component featuring QR Code generation & barcoding in .NET projects,
with which developers can easily integrate QR Code images in ASP.NET web forms, WinForms, C#.NET class & console applications.
Besides, the user-friendly interface provides easy access to customize generated QR Code images like size, orientation, resolution, and so on.
2D QR Code Barcode Description
QR Code, also named as Denso Barcode, QRCode, Quick Response Code, JIS X0510, ISO/IE18004, is a popular matrix barcode with fast readability and large storage capacity.
QR Code could be scanned by smart phones like Blackberry, iPhone, and Windows Phone 7.5.
- numeric data (digits 0 - 9)
- alphanumeric data (digits 0 - 9; upper case letters A -Z; nine other characters: space, $ % * + - . / : )
- byte data (default: ISO/IEC 8859-1)
- Kanji characters
Create GS1 Compatible QR Code
- Set FNC1 to KeepAutomation.Barcode.FNC1.First
- In barcode data setting CodeToEncode, around AI code with "()", and followed by AI data, such as "(02)225(03)33344". Here "02", "03" are the AI code, "225", "33344" is the AI data,
Encode Special Chars or Non-printable Chars in QR Code
- Set TildeEnabled to true
- Use '~ddd' for non-printable chars. For example, ASCII char [GS] is non-printable, and its decimal value is 29. In barcode data, you need use ~029 for char [GS].
The following C# source codes demo how to encode byte[] object in QR Code
// Byte array to encode
byte[] dataBytes = new byte[] { 0x41, 0x42, 0x43, 0x44, 0x45 };
// Convert byte array to the input (property CodeToEncode)
String inputMsg = "";
foreach (byte b in dataBytes)
inputMsg += "~" + b.ToString().PadLeft(3, '0');
// Create barcode
BarCode barcode = new BarCode();
barcode.Symbology = Symbology.QRCode;
barcode.QRCodeDataMode = QRCodeDataMode.Byte;
// enable '~' in the input message
barcode.TildeEnabled = true;
barcode.CodeToEncode = inputMsg;
// set module size to 5 pixels
barcode.BarcodeUnit = BarcodeUnit.Pixel;
barcode.X = 5;
barcode.Y = 5;
barcode.generateBarcodeToBitmap().Save(@"C:\QRCode_Bytes.png");
Encode non-English text in QR Code
The following C# source codes demo how to encode non English text (such as Thai text) in QR Code
// Message in Thai
String unicodeMsg = @"สวัสดีตอนเช้าค่ะ";
// Convert Unicode string to data bytes
byte[] dataBytes = Encoding.Unicode.GetBytes(unicodeMsg);
// Convert byte array to the input (property CodeToEncode)
String inputMsg = "";
foreach (byte b in dataBytes)
inputMsg += "~" + b.ToString().PadLeft(3, '0');
// Create barcode
BarCode barcode = new BarCode();
barcode.Symbology = Symbology.QRCode;
barcode.QRCodeDataMode = QRCodeDataMode.Byte;
// enable '~' in the input message
barcode.TildeEnabled = true;
barcode.CodeToEncode = inputMsg;
Generate Barcode Image in Specified Width and Height
- Set property AutoSizeAdjust to true
- Set property DPI to be the same or higher as your printer's resolution
- Set property BarcodeUnit to inch or cm
- Set property BarCodeWidth and BarCodeHeight to your required image width and height
QR Code Property Settings
Class Attribute
|
HTTP Attribute
|
Default Value
|
Note
|
Basic
|
Symbology
|
symbology
|
Code128Auto
|
Barcode symoblogy type.
QR Code is
KeepAutomation.Barcode.Symbology.QRCode
|
CodeToEncode
|
code-to-encode
|
"128"
|
Barcode data to encode.
|
ChecksumEnabled
|
checksum-enabled
|
false
|
It is not applied for QR Code.
|
ImageFormat
|
image-format
|
ImageFormat.Png
|
Barcode encoded image format.
|
Barcode Size
|
AutoSizeAdjust
|
auto-size-adjust
|
false
|
If true, barcode X, Y module will be auto-adjusted.
|
BarcodeUnit
|
barcode-unit
|
BarcodeUnit.Pixel
|
Unit of measure for all size related settings. 0: pixel; 1: inch; 2: cm.
|
X
|
x
|
1
|
Barcode module width (narrow bar).
|
Y
|
y
|
50
|
Linear barcode bar height / 2D barcode module height.
|
LeftMargin
|
left-margin
|
0
|
Barcode image left margin.
|
RightMargin
|
right-margin
|
0
|
Barcode image right margin.
|
TopMargin
|
top-margin
|
0
|
Barcode image top margin.
|
BottomMargin
|
bottom-margin
|
0
|
Barcode image bottom margin.
|
DPI
|
dpi
|
72
|
Barcode image resolution in dpi.
|
Orientation
|
orientation
|
Orientation.Degree0
|
Barcode rotation angle.
|
BarCodeWidth
|
barcode-width
|
0
|
Whole barcode width.
|
BarCodeHeight
|
barcode-height
|
0
|
Whole barcode height.
|
2D / Matrix Group Barcode Properties
|
GroupEnabled
|
group-enabled
|
false
|
Set to enable Data Matrix, PDF417, or QR Code group function.
|
GroupItemCount
|
group-item-count
|
0
|
Data Matrix, PDF417, or QR Code group count.
|
GroupItemId
|
group-item-id
|
0
|
Data Matrix, PDF417, or QR Code group item id.
|
GroupId
|
group-item-id
|
0
|
Data Matrix, PDF417, or QR Code group item.
|
QR Code Specific Settings
|
FNC1
|
fnc1
|
FNC1.None
|
To encode GS1 compatible QR Code, you need set value to "FNC1.First"
|
QRCodeDataMode
|
qrcode-data-mode
|
QRCodeDataMode.Auto
|
Set QR Code data encoding mode.
- QRCodeDataMode.Auto: It allows encoding all 256 possible 8-bit byte values. This includes all ASCII characters value from 0 to 127 inclusive and provides for international character set support
- QRCodeDataMode.AlphaNumeric: It allows encoding alphanumeric data (digits 0 - 9; upper case letters A -Z; nine other characters: space, $ % * + - . / : ).Web Stream URL Parameter: Encoding. Valid values are: 0 (Auto), 1 (AlphaNumeric), 2 (Byte), 3 (Numeric), 4 (Kanji).
- QRCodeDataMode.Byte: It allows encoding byte data (default: ISO/IEC 8859-1).
- QRCodeDataMode.Numeric: It allows encoding numeric data (digits 0 - 9).
- QRCodeDataMode.Kanji: It allows encoding Kanji characters.
|
QRCodeECL
|
qrcode-ecl
|
QRCodeECL.L
|
Set QR Code error correction level, including L, M, Q, H.
|
QRCodeVersion
|
qrcode-version
|
QRCodeVersion.V1
|
Set QR Code version, from V1 to V40.
|
QRCodeECI
|
qrcode-eci
|
3
|
QR Code column Extended Channel Interpretations. Valid values are from 000000 to 999999.
|
TildeEnabled
|
tilde-enabled
|
false
|
Set TildeEnabled to true, specifying special characters in barcode data.
Support escape '~' for data message
-
1-byte character: ~ddd (character value from 0 ~ 255)
ASCII (with EXT): from ~000 to ~255
For example, ASCII char [GS] is non-printable, and its decimal value is 29. In barcode data, you need use ~029 for char [GS].
- 2-byte character: ~6ddddd (character value from 0 ~ 65535)
- Unicode: from ~600000 to ~665535
- ECI: from ~7000000 to ~7999999
- SJIS: from ~9ddddd (Shift JIS 0x8140 ~ 0x9FFC and 0xE040 ~ 0xEBBF)
|
How to Generate QR Code in ASP.NET Using C#
This Barcode Generator control supports generating QR Code barcode images in ASP.NET web applications.
You can easily create QR Code in ASP.NET websites with control by dragging and dropping, stream QR Code barcode in website as url through Microsoft IIS,
or simple generate QR Code with Visual C# programming in ASP.NET web projects.
View
How to generate barcode in C#.NET using ASP.NET.
How to Create QR Code in .NET Windows Forms Using C#
Users can also paint and draw high-quality QR Code barcodes in .NET Windows Forms applications.
You can directly drag the barcoding control to a Windows Form and get a QR Code image or create barcodes with Visual C# programming.
For more details, please view
How to create barcode using C# in .NET WinForms.
How to Print QR Code in Crystal Reports Using C#
With this barcode component dll SDK, developers can easily generate multiple QR Code images in Crystal Reports.
This control is lightweight and easy to use with no barcode fonts or any third party tool needed. All barcode parameters are adjustable through simple C# programming.
View details here:
How to create barcode using Visual C# in Crystal Reports
How to Add QR Code in RDLC Reports Using C#
This .NET Barcode Generator for .NET also supports creating QR Code barcode images in Microsoft Visual Studio 2005 / 2008 / 2010 ReportViewer Local Reports (RDLC).
You can easily adjust QR Code settings through Visual C# programming. Please click the tutorial here for more details:
How to create barcode using C# in RDLC Reports.
How to Create QR Code in Class Library Using C#
Lastly, you can always resort to Visual C# code for easy QR Code barcode generation in .NET projects. Below is the C# sample code for you with some basic settings.
Please copy to your barcoding application for a test. You may make some adjustments for the
QR Code Parameters if necessary.
C# Sample code
BarCode qrcode = new BarCode();
qrcode.Symbology = KeepAutomation.Barcode.Symbology.QRCode;
//Select a QR Code supported data mode according to your code:
//AlphaNumeric: for 0 - 9, upper case letters A - Z, and nine punctuation characters space, $ % * + - . / :
//Byte data: for (ISO/IEC 8859-1) encoding characters at 8 bits per character
//Kanji Characters (JIS)
//Numeric: for digits 0 - 9
qrcode.QRCodeDataMode = QRCodeDataMode.Auto;
//Input your QR Code encoding data:
qrcode.CodeToEncode = "C#QRCodeGenerator";
// Unit of measure, pixel, cm and inch supported.
qrcode.BarcodeUnit = BarcodeUnit.Pixel;
// QR Code image resolution in dpi
qrcode.DPI = 72;
// QR Code bar module width (X dimention)
qrcode.X = 3;
// QR Code bar module height (Y dimention), Y=X
qrcode.Y = 3;
// QR Code image left margin size, the minimum value is 4X.
qrcode.LeftMargin = 12;
// Image right margin size, minimum value is 4X.
qrcode.RightMargin = 12;
// Image top margin size, minimum value is 4X.
qrcode.TopMargin = 12;
// Image bottom margin size, minimum value is 4X.
qrcode.BottomMargin = 12;
// QR Code orientation, 90, 180, 270 degrees supported.
qrcode.Orientation = KeepAutomation.Barcode.Orientation.Degree0;
// QR Code barcode version, valid from V1-V40
qrcode.QRCodeVersion = QRCodeVersion.V5;
// QR Code barcode Error Correction Lever, supporting H, L, M, Q.
qrcode.QRCodeECL = QRCodeECL.H;
// QR Code image formats, supporting Png, Jpeg, Gif, Tiff, Bmp, etc.
qrcode.ImageFormat = ImageFormat.Png;
// Generate QR Code barcodes in image format GIF
qrcode.generateBarcodeToImageFile("C://barcode-qrcode-csharp.png");
/* Create QR Code barcodes in Stream object
qrcode.generateBarcodeToStream(".NET System.IO.Stream Object");
Draw & Print QR Code barcodes to Graphics object
qrcode.generateBarcodeToGraphics(".NET System.Drawing.Graphics Object");
Generate QR Code barcodes & write to byte[]
byte[] barcodeInBytes = qrcode.generateBarcodeToByteArray();
Generate QR Code barcodes & encode to System.Drawing.Bitmap object
Bitmap barcodeInBitmap = qrcode.generateBarcodeToBitmap();
*/