.NET Barcode for WinForms          ASP.NET Barcode          .NET Barcode Reader          Java Barcode          Java Barcode Reader
Avapose > QR Code Introduction > QR Code Size Setting > QR Code Size Setting in C#

QR Code C# Size Setting

QR Code Generator Size Setting, Generate & Create QR Code in C#, ASP.NET, VB.NET

A typical QR Code barcode symbology consists of quiet zone, finder pattern, (timing pattern), separator, and the encoding region (for format & version information and data & error correction code words).

As a result, the symbol width of a QR Code can be calculated with the formula:



QR COde




W
= [ 8 * 2 + ( 4V + 1) ] X + 2Q

W: barcode width of QR Code (including quiet zone)
H: barcode height of QR Code (including quiet zone)
V: version of the QR Code (1<=V<=40)
X: module width of QR Code
Q: width of quiet zone; Q = 4X


C# Size Setting



With the formula above, there will be three ways to set the size of a QR Code image in C#. Here are the methods and respective examples.

Method 1. Setting the X Dimension


Setting in C# generator

Steps:

  • Set the X dimension

  • Set AutoResize to false

  • Adjust other properties


Sample:
QRCode.X=4;
QRCode.Y=4;
QRCode.AutoResize=false;
QRCode.Data = "AvaposeProduct";
The rest of barcode settings are in default value.
Here is the generated QR Code barcode:




Method 2. Setting the Barcode Width



Setting in C# generator

Steps:

  • Set the barcode width

  • Set AutoResize to true

  • Adjust other properties


Sample:
QRCode.BarcodeImageWidth=140;
QRCode.BarcodeImageHeight=140;
QRCode.AutoResize=true;
QRCode.Data =" AvaposeQRCode ";
The rest of barcode settings are in default value.
Here is the generated QR Code barcode:


According to the formula above, the maximum X dimension is 5 pixel for this QR Code.


Method 3. Setting both X Dimension and Symbol Width


Setting in C# generator

Steps:

  • Set the X dimension

  • Set the barcode width

  • Set AutoResize to false

  • Adjust other properties


Sample:
QRCode.X=2;
QRCode.Y=2;
QRCode.AutoResize=false;
QRCode.BarcodeImageWidth=50;
QRCode.BarcodeImageHeight=50;
QRCode.Data ="qrcodeavapose";
The rest of barcode settings are in default value.
Here is the generated QR Code barcode:




Attention: Please note that once you have set an X dimension, there will always be a minimum barcode width as calculated from the calculation above. Therefore, if the W you have set is less than the minimum value, Avapose QR Code generators will reset the barcode width to a minimum value according to the standard. Here is an example:


If you set in C# QR Code generator:
QRCode.X=6;
QRCode.Y=6;
QRCode.BarcodeImageWidth=150;
QRCode.BarcodeImageHeight=150;
QRCode; Data ="easytouse";
The rest of barcode settings are in default value


According to the formula above,
W = [ 8 * 2 + ( 4V + 1) ] X + 2Q
//X=6pixel, V=1(default),
Q=0 (default 0 by Avapose)
Wmin= [8*2+(4+1)]*6
        =126 pixel

However, the BarcodeImageWidth (100 pixel) you have set in C# generator is less than the minimum barcode width (126pixel), so the generator will automatically reset it to 126 pixel according to standard. Here is the generated barcode image:

On the other hand, if you set a barcode width larger than the minimum W calculated by the formula, extra spaces will be added to either side of the quiet zones.


For instance,
if you set in your C # generator:
QRCode.X=6;
QRCode.BarcodeImageWidth=150;
QRCode.BarcodeImageHeight=150;
QRCode; Data ="easytouse";
The rest of barcode settings are in default value.


According to the formula,
W = [ 8 * 2 + ( 4V + 1) ] X + 2Q
//X=6pixel, V=1(default),
Q=0 (default 0 by Avapose)
Wmin= [8*2+(4+1)]*6
        =126 pixel

Now your W setting is 150 pixel, which is larger than the minimum width, so an extra 12 pixel will be added to both side of the quiet zone. Here is the barcode image:

QR Code barcode size custom in C# for various barcode solutions