The package Micro QRCode contains the classes you need to create Micro QRCode barcodes within your .NET applications.
The Micro QR Code format (also specified in the International Standard), is a variant of QR Code with a reduced number of overhead modules and a restricted range of sizes. A single finder pattern, is located at the upper left corner of the symbol as illustrated in the following figure.
Micro QR Code symbols have 4 version (version 1 to 4). The sizes of the barcodes are:
version M1: 11 x 11 modules.
version M2: 13 x 13 modules.
version M3: 15 x 15 modules.
version M4: 17 x 17 modules.
The maximum barcode capacity of Micro QR Code the largest barcode symbol size, (Version 4 error correction level L):
numeric data (digits 0-9): 35 characters
aphanumeric data (digits 0 - 9 , upper case letters A -Z and nine other characters: space, $ % * + - . /): 21 characters
Byte data ( (bytes 0-255): 15 characters
Kanji data ( hexadecimal values 8140 -9FFC and E040 - EBBF ): 9 characters
Supports 4 error correction levels:
In order to run the sample application you must execute QRCodeDemo20.exe or QRCodeDemo4.exe.
In the sample application you can set all properties of the Micro QRCode symbology.
You can execute the following commands:
- Refresh: repaint the symbol using the new properties.
- Print: send image to printer.
- Save: save the symbol in gif format.
- Exit: terminate application.
Micro QRCode class
The main class for creating Micro QRCode barcodes is J4L.MicroQRCode.MicroQRCode. It is a subclass of System.Windows.Forms.Control and can therefore be used for placing a barcode on a windows form.
The following properties allows you to configurate the barcode:
- AutoConfigurate: if true the preferredVersion can be ignored if the data does not fit in the selected version.
- BarBackColor: background color.
- BarForeColor: foreground color (color of the bars).
- BinaryCode: sets the value to be encoded as an array of integers.
- Code: string to be encoded.
- Encoding: encoding mode (default is AUTO). Valid values are:
- AUTO: Automatic selecting of the encoding method.
- ALPHA: encode alpahnumeric characters only (upper case letter plus 9 additional characters).
- NUMERIC: encode alpahnumeric digits only.
- BYTE: use this mode to encode binary data.
- KANJI: encodes Kanji characters only.
- ErrorCorrectionLevel: Valid values are:
- CORRECTION_LEVEL_L (default). About 7% recovery capacity.
- CORRECTION_LEVEL_M: About 15% recovery capacity.
- CORRECTION_LEVEL_Q: About 25% recovery capacity.
- getCurrentX (read only): final position of the cursor. Use this properry to find out the size of the image in pixels.
- getCurrentY (read only): final position of the cursor. Use this properry to find out the size of the image in pixels.
- Margin: left and top margin in pixels (default is 30).
- ModuleSize: number of pixels which make a module (square) in the barcode (default is 4).
- PreferredVersion: preferred format. Another version will be automatically selected if AutoConfigurate=true and the amount of data and the selected error correction level does not fit in the preferred version. Valid values are 1 to 4.
- ProcessTilde: if true (default) the tilde character (~) will be processed like this:
- ~~: will be replaced with ~
- ~dxxx: will be replaced by the character whose ascii code is xxx. For example ~d065 will be replaced with A.
- Redraw: set this property to true if you need to rebuild the barcode.
The following method can be used for painting the barcode on an external graphics object:
- public void paint(Graphics g): paints the Micro QRCcode symbol.
If you need to created a image file you can do it like this:
[C#]
using J4L.QMicroRCode;
...
// define variable
MicroQRCode bc;
// create instance of the objact
bc = new MicroQRCode();
// set barcode properties
bc.Code="12345678";
...
// set size and write to file
bc.Size = new System.Drawing.Size(368, 176);
bc.saveToFile("qrcode.gif","GIF");
[VBNET]
Imports J4L.MicroQRCode
......
' define variable
Dim bc as MicroQRCode
'create instance of the object
bc = new MicroQRCode()
' set barcode properties
bc.Code="12345678"
...
' set size and write to file
bc.Size = new System.Drawing.Size(368, 176)
bc.SaveToFile("qrcode.gif","GIF")
You can also use the paint() method for rendering the barcode onto an external Graphics object:
[C#]
using J4L.MicroQRCode;
using System.Drawing;...
// create image and graphics
Bitmap inMemoryImage =new Bitmap(300,300) ;
Graphics g= Graphics.FromImage(inMemoryImage) ;
// create barcode
MicrpQRCode bc=new MicroQRCode();// set barcode properties
bc.Size=new Size(300,300);
bcCode="12345678";
...
// render barcode on "g"
bc.paint(g);[VBNET]
Imports J4L.MicroQRCode
Imports System.Drawing..............
' create image and graphics
dim inMemoryImage as new Bitmap(300,300)
dim g as Graphics = Graphics.FromImage(inMemoryImage)
'create barcode
dim bc as MicroQRCode =new MicroQRCode()' set barcode properties
bc.Size=new Size(300,300);
bc.Code="12345678"
...
'render barcode on "g"
bc.paint(g)The windows forms control can be placed on a form with your IDE by just adding our controls to the toolbox. You can also programatically add controls to your form with the following code:
[C#]
using J4L.MicroQRCode;
...
// define variable
MicroQRCode bc;
// create instance of the objact
bc = new MicroQRCode();
// define position and size of the object on the form
bc.Location = new System.Drawing.Point(8, 8);
bc.Size = new System.Drawing.Size(368, 176);// set barcode properties
bc.Code="12345678";
....
// add it to the form "this" is the current form.
this.Controls.Add(bc);[VBNET]
Imports J4L.MicroQRCode
.....
' define variable
dim bc as MicroQRCode
'create instance of the objact
bc = new MicroQRCode()
'define position and size of the object on the form
bc.Location = new System.Drawing.Point(8, 8)
bc.Size = new System.Drawing.Size(368, 176)' set barcode properties
bc.Code="12345678";
...
'add it to the form "me" is the current form.
me.Controls.Add(bc)You can print the barcode by rendering in on the Graphics objects of the PrintDocument:
[C#]
void btnPrintClick(object sender, System.EventArgs e)
{
// create PrintDocument and set handler
PrintDocument printDocument1=new PrintDocument();
printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
printDocument1.Print();
}private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
// print barcode here
bc.paint(e.Graphics);
}
Table — Data capacity for Micro QRCode versions
Version
|
Error
Correction Level
|
Numeric |
Alphanumeric |
Byte |
Kanji |
1 |
|
5 |
- |
- |
- |
2 |
L |
10 |
6 |
- |
- |
3 |
L |
23 |
14 |
9 |
6 |
4 |
L |
35
|
21
|
15
|
9 |
Alphanumeric mode is not available in Version M1 Micro QR Code symbols.
Byte mode is not available in Version M1 or M2 Micro QR Code symbols.
Kanji mode is not available in version M1 or M2 Micro QR Code symbols.