C# .NET Core QR Code Generator is one of the functions in OnBarcode's
Barcode for .NET Core Generation Controls,
which supports generating & printing QR Code and 20+ other linear & 2D bar codes for C# .NET Core applications.
OnBarcode C# .NET Core Barcode Generator makes it easy to generate, create QR Code and other linear & 2d barcodes in
.NET Core web and windows projects. Here are some detailed tutorials for C# QR Code generation and data encoding, size & image setting.
This document is providing a detailed C# source code about generating QR Code barcodes in .NET Core C# class using
C# .NET Core Barcode Generate
generation component.
using System;
using System.Collections.Generic;
using System.Text;
using OnBarcode.Barcode;
using System.Drawing.Imaging;
using System.Drawing;
QRCode qrcode = new QRCode();
// Barcode data to encode
qrcode.Data = "ONBARCODE";
// QR-Code data mode
qrcode.DataMode = QRCodeDataMode.AlphaNumeric;
// QR-Code format mode
//qrcode.Version = QRCodeVersion.V10;
/*
* Barcode Image Related Settings
*/
// Unit of meature for all size related setting in the library.
qrcode.UOM = UnitOfMeasure.PIXEL;
// Bar module size (X), default is 3 pixel;
qrcode.X = 3;
// Barcode image left, right, top, bottom margins. Defaults are 0.
qrcode.LeftMargin = 0;
qrcode.RightMargin = 0;
qrcode.TopMargin = 0;
qrcode.BottomMargin = 0;
// Image resolution in dpi, default is 72 dpi.
qrcode.Resolution = 72;
// Created barcode orientation.
//4 options are: facing left, facing right, facing bottom, and facing top
qrcode.Rotate = Rotate.Rotate0;
// Generate QR-Code and encode barcode to gif format
qrcode.ImageFormat = System.Drawing.Imaging.ImageFormat.Gif;
qrcode.drawBarcode("C:\\qrcode.gif");
/*
You can also call other drawing methods to generate barcodes
public void drawBarcode(Graphics graphics);
public void drawBarcode(string filename);
public Bitmap drawBarcode();
public void drawBarcode(Stream stream);
*/
Category |
Properties |
Value |
Comments |
Basic |
Property: Data
URL: DATA
|
Type: string
Default: "QRCode"
|
Barcode value to encode.
QRCode Valid Data Char Set:
- 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
|
|
QRCode Special |
Property: ProcessTilde
URL: PROCESS-TILDE
|
Type: bool
Default: true
|
Set the ProcessTilde property to true, if you want use the tilde character "~" to specify special characters in the input data. Default is true.
|
Property: DataMode
URL: DATA-MODE
|
Type: QRCodeDataMode
Default: QRCodeDataMode.Auto (0)
|
-
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, $ % * + - . / : ).
-
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.
|
Property: ECL
URL: ECL
|
Type: QRCodeECL
Default: QRCodeECL.L (0)
|
QRCode Error Correction Level. Default is QRCodeECL.L (0).
- QRCodeECL.L (0)
- QRCodeECL.M (1)
- QRCodeECL.Q (2)
- QRCodeECL.H (3)
|
Property: FNC1
URL: FNC1
|
Type: FNC1
Default: FNC1. FNC1_NONE (0)
|
To encode GS1 compatible QR-Code barcode, you need set FNC1 value to FNC1.FNC1_1ST_POS (1).
|
Property: StructuredAppend
URL: STRUCTURED-APPEND
|
Type: bool
Default: false
|
Set StructuredAppend property to true, then Structured Append is enabled. |
Property: SymbolCount
URL: SYMBOL-COUNT
|
Type: int
Default: 0
|
the number of total symbols which make the sequence. |
Property: SymbolIndex
URL: SYMBOL-INDEX
|
Type: int
Default: 0
|
the position of current symbol in the secuence (Start with 0). |
Property: Parity
URL: PARITY
|
Type: int
Default: 0
|
- |
Property: Version
URL: VERSION
|
Type: QRCodeVersion
Default: QRCodeVersion.V1 (1).
|
Valid values are from V1 to V40. |
|
Barcode Size Related |
Property: AutoResize
URL: AUTO-RESIZE
|
Type: bool
Default: false
|
Auto resize the generated barcode image.
|
Property: BarAlignment
URL: BAR-ALIGNMENT
|
Type: int
Default: 1 (center)
|
Barcode horizontal alignment inside the image. 0: left, 1: center, 2: right. |
Property: UOM
URL: UOM
|
Type: UnitOfMeasure
Default: PIXEL (0)
|
Unit of meature for all size related settings in the library.
Valid values:
- UnitOfMeasure.PIXEL (0)
- UnitOfMeasure.CM (1)
- UnitOfMeasure.INCH (2)
|
Property: X
URL: X
|
Type: float
Default: 2
|
Barcode bar module width and height, default is 3 pixel. |
Property: BarcodeWidth
URL: BARCODE-WIDTH
|
Type: float
Default: 0.
|
Barcode image width.
If BarcodeWidth setting is smaller than the barcode required minimum width, the library will automatically reset to barcode minimum width. |
Property: BarcodeHeight
URL: BARCODE-HEIGHT
|
Type: float
Default: 0.
|
Barcode image height.
If BarcodeHeight setting is smaller than the barcode required minimum height, the library will automatically reset to barcode minimum height. |
Property: LeftMargin
URL: LEFT-MARGIN
|
Type: float
Default: 0.
|
Barcode image left margin size. |
Property: RightMargin
URL: RIGHT-MARGIN
|
Type: float
Default: 0.
|
Barcode image right margin size. |
Property: TopMargin
URL: TOP-MARGIN
|
Type: float
Default: 0.
|
Barcode image top margin size. |
Property: BottomMargin
URL: BOTTOM-MARGIN
|
Type: float
Default: 0.
|
Barcode image bottom margin size. |
Property: Resolution
URL: RESOLUTION
|
Type: int
Default: 72.
|
Barcode image resolution in DPI (Dots per inch). |
Property: Rotate
URL: ROTATE
|
Type: Rotate
Default: Rotate.Rotate0 (0).
|
Valid values:
- Rotate.Rotate0 (0)
- Rotate.Rotate90 (1)
- Rotate.Rotate180 (2)
- Rotate.Rotate270 (3)
|
|
Barcode Colors |
Property: BackColor
URL: BACK-COLOR
|
Type: Color
Default: white
|
Barcode image background color. |
Property: ForeColor
URL: FORE-COLOR
|
Type: Color
Default: black
|
Barcode image foreground color.
|
|
In WebStream query string, please use int value for Enums, "true" and "false" for bool. |