Our Customers
Contact Us Email: support@barcodelib.com
Home > .NET Barcode > C# Barcoding Guide > How to Encode Unicode into Barcode with Visual C#.NET
Download Barcode for .NET Suite Trial

How to customize barcode size using C#?

Detailed C# developer guide to create, customize barcode with required barcode dimension size using C# barcode generator


Quick to create, customize 2d barcode size in C#
When you are creating QR Code or barcodes using BarcodeLib C# barcode library, the barcode generator library will generate a barcode image with default barcode dimension width and height. The default barcode size is decided by barcode format, input encoding data length.

The C# example code below shows how to create a QR Code encoding a site url data with default dimension width/height. (The printed barcode image is in 336 pixels x 336 pixels)

            QRCode qrcode = new QRCode();
            qrcode.Data = "https://www.barcodelib.com";
            qrcode.drawBarcode("C://output//csharp-quick-start-qrcode.png");


You can easily customize the barcode with your target width and height.
  • UOM: Unit of measure. You can choose one of the following values: "PIXEL", "INCH", "CM". The default value is Pixel.
  • ImageWidth: set the generated barcode image width
  • ImageHeight: set the barcode image height
Using the following C# source code, you will get a QR Code with same data encoded in 200 pixels width and 200 pixels height.

            QRCode qrcode = new QRCode();
            qrcode.Data = "https://www.barcodelib.com";
            qrcode.UOM = UnitOfMeasure.PIXEL;
            qrcode.ImageWidth = 200;
            qrcode.ImageHeight = 200;
            qrcode.drawBarcode("C://output//csharp-create-barcode-size-qrcode-simple-setting.png");




Quick to encode, customize 1d barcode size in C#
1D barcode dimesnsion size setting is similar with QR Code and other 2d barcodes. However sometimes you need customize the printed barcode text below the bar modules.

Here we use the C# codes below to create a Code 128 barcode image with default barcode module and text width and height in the C# program.

            Linear code128 = new Linear();
            code128.Type = Barcode.BarcodeType.CODE128;
            code128.Data = "CODE 128";
            code128.drawBarcode("C://output//csharp-quick-start-code128.png");


The printed barcode image size is 572 pixels in width, and 250 pixels in height.



Here we will resize the generated Code 128 barcode image width to 200 pixel through barcode property ImageWidth. And the printed barcode image height will be automatically resized to 87 pixels.

            Linear code128 = new Linear();
            code128.Type = Barcode.BarcodeType.CODE128;
            code128.Data = "CODE 128";
            code128.ImageWidth = 200;
            code128.drawBarcode("C://output//csharp-create-barcode-size-code128-customized-setting.png");






Here we will change the barcode text size to 16 points.
  • ResizeText: Set to false. If true, the barcode library will ignore the text size related settings, and automatically choose the right font size.
  • TextFont : set the font size to 9 points.
            Linear code128 = new Linear();
            code128.Type = Barcode.BarcodeType.CODE128;
            code128.Data = "CODE 128";
            code128.ResizeText = false;
            code128.TextFont = new Font("Arial", 9);
            code128.ImageWidth = 200;
            code128.drawBarcode("C://Projects//Test-Output//BarcodeLib.com//csharp-create-barcode-size-code128-customized-font-setting.png");






Barcode dimension size related properties in C#
  • ResizeImage. Default is true. If true, the barcode library will choose the maximum bar module width and height, based on the default or specified ImageWidth, ImageHeight, barcode format, encoding data length.
  • ResizeText: Default is true. If true, the barcode library will ignore the text size related settings, and automatically choose the right font size.

  • UOM: Unit of measure. You can choose one of the following values: "PIXEL", "INCH", "CM". The default value is Pixel.
  • ImageWidth: The generated barcode image width.
  • ImageHeight: The generated barcode image height.
  • BarWidth: The generated barcode module width. If ResizeImage is true, the property will be ignored.
  • BarHeight: The generated barcode module height. If ResizeImage is true, the property will be ignored.

  • LeftMargin: Default is 0f. The margin space on the left side of the bar modules.
  • RightMargin: Default is 0f. The margin space on the right side of the bar modules.
  • TopMargin: Default is 0f. The margin space on the top of the bar modules.
  • BottomMargin: Default is 0f. The margin space on the bottom of the bar modules.

  • TextMargin: For 1d barcode formats only, the margin space between bar modules and text label.
  • TextFont: For 1d barcode formats only, The font size settings.












Barcode for Visual C#.NET - Other Supported Barcodes
Linear / 1D Barcodes:
Matrix / 2D Barcodes: