KA.Barcode Generator for .NET Suite
How to Create & Resize Code 128 in C#
Complete C#.NET source code to generate Code 128 images and change barcode size with .NET Control
  • Print, generate Code 128A, Code 128B, Code 128C in .NET framework 2.0, 3.0, 3.5 and above versions
  • Draw, print Code 128 in ASP.NET web applications, WinForms, Crystal Reports, C#.NET class
  • Insert linear and GS1 barcodes , such as ITF-14 .NET WinForms, ASP.NET EAN-8, UPC-A .NET, ASP.NET EAN-13, in your applications
  • Compatible with latest ISO/IEC 15417 Code 128 bar code symbology specification for valid image output
  • Create, draw Code 128 images in Png, Jpg, Gif, Tiff, Bmp formats and save to image files
  • Checksum digit automatically calculated and added for Code 128 according to specification requirements
  • Support encoding, creating Code 128 bar codes in Pixel, Cm or Inch as unit of measure
  • Powerful barcode component barcode ASP.NET, barcode .NET, Java barcode developed for easy barcode creation
  • Support adjusting Code 128 X dimension, i.e. Code 128 module width in C#.NET
Code 128 is also named as ANSI/AIM 128, Uniform Symbology Specification Code 128, USS Code 128. This page offers complete C# source code for Code 128 barcode generation in C# and size setting through various barcode parameters.
Install KA.Barcode Generator for .NET Suite into C#.NET Project
  1. 1.
  2. 2.
    Add Reference: Add "KeepAutomation.Barcode.Window.dll" to your C#.NET project reference.
How to Generate, Resize Code 128 Images in C# Class
Copy the following C#.NET Code onto your project to create a Code 128 barcode image
using KeepAutomation.Barcode.Bean;

BarCode code128= new BarCode();
code128.Symbology = KeepAutomation.Barcode.Symbology.Code128C;
code128.CodeToEncode = "0128";
code128.X =2;
code128.generateBarcodeToImageFile("C:/code128_csharp.png");

code128_image

Code 128 Barcode Unit

By default, all parameters are measured in Pixel for KA.Barcode Generator for .NET Suite. Other supported units of measure include Cm and Inch. Adjust this property through the following C#.NET setting.
code128.BarcodeUnit = BarcodeUnit.Cm;       

Code 128 X Dimension (Bar Width)

The property X dimension stands for the width of a Code 39 module bar, which is actually the width of the narrowest bar. This float value is 1 pixel by default. You can change it with the C#.NET demo code below.
code128.X = 2;

Code 128 Y Dimension (Bar Height)

The property Y dimension is the bar height of a Code 128 image, with the default value being 50 pixels. Please follow the C#. NET sample code below to adjust this parameter.
code128.Y = 55;

Code 128 Barcode Width and Barcode Height

KeepAutomation C# Code 128 generator also allows you to adjust the image width as well as barcode height. Though default value for the two is 0, KA.Barcode will automatically print valid Code 128 image in C#.NET. If you want to customize these two parameters, please copy the sample code below.
code128.BarCodeWidth = 300;
code128.BarCodeHeight = 70;
Please note that once you have input encoding data and set X dimension, you can actually calculate a minimum Code 128 image width according to the encoding pattern specified in the Code 128 ISO/IEC standard. If the barcode width you set is less than the minimum value, KA.Barcode will print a valid Code 128 with the minimum width for image readability.

In this case, you can either assign a greater value to Code 128 or reduce data or X value so the image width goes along with your setting barcode width.