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

Code 128 C# Size Setting

Barcode Generator Size Setting, generate & create Data Matrix in C#, ASP.NET, VB.NET applications

The components of Code 128 barcode are Quiet zone, Start character, Data characters, Check digit, Stop character and Quiet zone.

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


Code 128




W
= 11 X ( C + D/2 ) + 2Q + 2X


W: the width of Code 128.
C: the number of start, special, symbol check and stop
characters plus the number of the data characters not
included in D
X: width of a module bar; X min=1 pixel
Q: width of the quiet zone; Q min=10X
D: number of numeric data characters encoded in double density
(Code Set C)


C# Size Setting



With the formula above, there will be three ways to set the size of an Code 128 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:
Code128Auto.Symbology = Symbology.Code128Auto;
Code128Auto.Data = "3456";
Code128Auto.X = 3;
Code128Auto.AutoResize = false;
Other properties: default;
The generated Code 128 image is:



Method 2. Setting the Barcode Width


Setting in C# generator

Steps:

  • Set the barcode width

  • Set AutoResize to true

  • Adjust other properties


Sample:

Code128Auto.BarcodeImageWidth = 300;
Code128Auto.BarcodeImageHeight = 75;
Code128Auto.AutoResize = true;
Other properties: default;
The generated Code 128 image is:


According to the formula above, the maximum X dimension is 3 pixel for this Code 128 barcode.


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:
Code128Auto.Data = "3456";
Code128Auto.X = 2;
Code128Auto.BarcodeImageWidth = 200;
Code128Auto.AutoResize = false;
Other properties: default;
The generated Code 128 image is:



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 Code 128 Generators will reset the barcode width to a minimum value according to the standard. Here is an example:


If you set in C# Code 128 generator:
Code128.X=2;
Code128.W=120
Code128; Data ="3456";
The rest of barcode settings are in default value

According to the formula above,
W = 11X(C+D/2)+2Q+2X
//X=2pixel, C= 3, N=2(default), Q min=10*2=20 pixel
W min= 11*2 ( 3 + 4/2 ) +40+4
=154pixel

However, the W (120 pixel) you have set in C# generator is less than the minimum barcode width (154pixel), so the generator will automatically reset it to 154 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:
Code128.X=4;
Code128.W=350;
Code128;,Data ="3456";
The rest of barcode settings are in default value.


According to the formula,
W = 11X(C+D/2)+2Q+2X
//X=4pixel,C=3,N=2(default),Q min=10*2=20 pixel
W min= 11*4 ( 3 + 4/2 ) +80+8
= 308 pixel

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

Code 128 size custom in C# for various barcode solutions