IRONSOFTWAREHOME

Customize and Style Barcodes in C# for .NET with IronBarcode

Hairil Hasyimi Bin Omar
Hairil Hasyimi Bin Omar
Updated: July 21, 2026

IronBarcode enables developers to customize barcodes in C# by changing colors, resizing dimensions, and adding annotations, with simple method calls like ChangeBarCodeColor() and ResizeTo() for complete styling control.

Over the years, barcode usage has become increasingly popular and is used in a wide range of applications, whether storing data, IDs, or webpage URLs. In some applications, barcodes are made visible on products, resulting in an increased demand for styling options. Therefore, some barcode types have developed unique appearances such as PDF417, Aztec, IntelligentMail, MaxiCode, DataMatrix, and many more. For a comprehensive list of supported formats, see our Supported Barcode Formats documentation.

In addition, IronBarcode provides users with options to further style barcodes, including aspects like barcode colors, barcode resize, and background colors. This is made possible with the assistance of our open-source library, IronDrawing. These styling capabilities build upon IronBarcode's comprehensive barcode generation features.

Quickstart: Customize Barcode Color & Background

Here's a simple example showing how developers can quickly apply custom colors to a barcode's bars and background using IronBarcode. You'll see how easy it is to generate a styled barcode with just one chained call. For more advanced examples, check our C# Barcode Image Generator tutorial.

  1. 1Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. 2Copy and run this code snippet.

    IronBarCode.BarcodeWriter.CreateBarcode("HELLO123", IronBarCode.BarcodeEncoding.Code128)
        .ChangeBarCodeColor(IronSoftware.Drawing.Color.Blue)
        .ChangeBackgroundColor(IronSoftware.Drawing.Color.White)
        .SaveAsImage("styled.png");
    C#
  3. 3Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    arrow pointer

How Do I Resize a Barcode?

When Should I Use the ResizeTo Method?

Resizing a barcode is one aspect of customization that users can achieve with IronBarcode. To use this feature, simply call the ResizeTo method and input the new width and height measurements in pixels (px) for the barcode. This action triggers a lossless re-rendering of the barcode. This method maintains the barcode's quality while adjusting its dimensions, making it perfect for scenarios where you need to fit barcodes into specific layouts or print sizes.

Please note: Values that are too small for the barcode to be readable will be ignored.
using IronBarCode;

public class BarcodeResizer
{
    public static void ResizeBarcode(string barcodeText, int newWidth, int newHeight)
    {
        // Generate a barcode
        BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
                     // Resize the barcode
                     .ResizeTo(newWidth, newHeight)
                     // Save the resized barcode
                     .SaveAsImage("resized_barcode.png");
    }
    
    // Example usage with different size requirements
    public static void ResizeForDifferentFormats()
    {
        var barcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128);
        
        // Resize for product label
        barcode.ResizeTo(200, 50).SaveAsImage("product_label.png");
        
        // Resize for shipping label
        barcode.ResizeTo(300, 75).SaveAsImage("shipping_label.png");
        
        // Resize for inventory tag
        barcode.ResizeTo(150, 40).SaveAsImage("inventory_tag.png");
    }
}

The ResizeTo method is invoked on the GeneratedBarcode object. When working with different output formats, you might also want to explore our Create Barcode as PDF guide. Below are the barcode images generated by running the code snippet above.

Original barcode with standard dimensions before resize operation
Resized barcode showing clear black and white vertical bars after dimension modification

Why Use ResizeToMil Method for 1D Barcodes?

Another aspect of resizing available in IronBarcode is the ResizeToMil method. Unlike the ResizeTo method, this one adjusts the following components:

  • Barcode element: The width of the narrowest barcode element, measured in thousandths of an inch (mil).
  • Height: The height of the barcode, measured in inches (the default is 1 inch).
  • Resolution: Dots per inch (the default is 96 DPI).

This method is particularly suitable for 1D barcodes and is commonly used in industrial applications where precise measurements are critical. The mil measurement system is an industry standard that ensures consistent barcode readability across different scanners and printing conditions.

using IronBarCode;

public class BarcodeResizer
{
    public static void ResizeBarcodeToMil(string barcodeText, int elementWidthMil, int heightInches, int dpi = 96)
    {
        // Generate a barcode
        BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128)
                     // Resize the barcode to mil
                     .ResizeToMil(elementWidthMil, heightInches, dpi)
                     // Save the resized barcode
                     .SaveAsImage("resized_barcode_mil.png");
    }
    
    // Example for different industrial standards
    public static void CreateIndustrialBarcodes()
    {
        // Standard retail barcode (10 mil width, 1 inch height)
        BarcodeWriter.CreateBarcode("RETAIL-001", BarcodeEncoding.Code128)
                     .ResizeToMil(10, 1, 300)
                     .SaveAsImage("retail_barcode.png");
        
        // High-density warehouse barcode (5 mil width, 0.5 inch height)
        BarcodeWriter.CreateBarcode("WAREHOUSE-002", BarcodeEncoding.Code128)
                     .ResizeToMil(5, 0.5f, 600)
                     .SaveAsImage("warehouse_barcode.png");
        
        // Large shipping barcode (15 mil width, 2 inch height)
        BarcodeWriter.CreateBarcode("SHIP-003", BarcodeEncoding.Code128)
                     .ResizeToMil(15, 2, 200)
                     .SaveAsImage("shipping_barcode.png");
    }
}

You can also call this method on the GeneratedBarcode object. For more information on setting precise barcode dimensions, refer to our Set Barcodes Margins guide. In the image below, you'll see the effects of applying the ResizeToMil method: the white spaces at the edges of the barcode are eliminated, and both the narrowest element and the height of the barcode are adjusted according to the parameter values provided to the method.

Original barcode with standard dimensions before ResizeToMil method is applied
Linear barcode showing result after ResizeToMil method application with vertical black and white bars

How Can I Change Barcode and Background Colors?

One of the most sought-after features for styling barcodes is the ability to change both the barcode and background colors. Thanks to IronDrawing, IronBarcode provides this capability. By using both the ChangeBarCodeColor and ChangeBackgroundColor methods on the GeneratedBarcode object, users can alter the colors of the barcode and its background. This feature is particularly useful for branding purposes or when creating themed barcodes for special events or product lines.

using IronBarCode;
using IronSoftware.Drawing; // Required for color manipulation

public class BarcodeColorChanger
{
    public static void ChangeBarcodeColors(string barcodeText, Color barcodeColor, Color backgroundColor)
    {
        // Generate a barcode
        var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);

        // Change the barcode color
        barcode.ChangeBarCodeColor(barcodeColor);

        // Change the background color
        barcode.ChangeBackgroundColor(backgroundColor);

        // Save the colored barcode
        barcode.SaveAsImage("colored_barcode.png");
    }
    
    // Example: Create branded barcodes with company colors
    public static void CreateBrandedBarcodes()
    {
        // Company brand colors example
        var barcode = BarcodeWriter.CreateBarcode("BRAND-2024", BarcodeEncoding.Code128);
        
        // Apply brand colors
        barcode.ChangeBarCodeColor(Color.FromHex("#1E3A8A")) // Company blue
               .ChangeBackgroundColor(Color.FromHex("#F3F4F6")) // Light gray background
               .SaveAsImage("branded_barcode.png");
        
        // Create seasonal variation
        var seasonalBarcode = BarcodeWriter.CreateBarcode("HOLIDAY-2024", BarcodeEncoding.Code128);
        seasonalBarcode.ChangeBarCodeColor(Color.DarkGreen)
                       .ChangeBackgroundColor(Color.LightYellow)
                       .SaveAsImage("seasonal_barcode.png");
    }
}

When working with colored barcodes, it's important to maintain sufficient contrast between the barcode and background colors to ensure readability. For more styling options specific to QR codes, see our Customize and Style QR Codes tutorial.

QR code with custom green background and tan foreground colors demonstrating barcode color customization

How Do I Add Annotations to a Barcode?

IronBarcode also provides the option to add and style barcode annotations. The styling for annotations is also assisted by the functionality from IronDrawing, including editing the annotation color and fonts. Annotations are essential for providing human-readable information alongside the machine-readable barcode, making them crucial for inventory management, product labeling, and shipping applications.

using IronBarCode;
using IronSoftware.Drawing; // Required for font and color manipulation

public class BarcodeAnnotator
{
    public static void AnnotateBarcode(string barcodeText, string annotationText, Font annotationFont, Color annotationColor, float annotationSpacing)
    {
        // Generate a barcode
        var barcode = BarcodeWriter.CreateBarcode(barcodeText, BarcodeEncoding.Code128);

        // Add annotation above the barcode
        barcode.AddAnnotationTextAboveBarcode(annotationText, annotationFont, annotationColor, annotationSpacing);

        // Add barcode value text below the barcode
        barcode.AddBarcodeValueTextBelowBarcode(annotationFont, annotationColor, annotationSpacing);

        // Save the annotated barcode
        barcode.SaveAsImage("annotated_barcode.png");
    }
    
    // Example: Create product label with annotations
    public static void CreateProductLabel()
    {
        var productCode = "PRD-12345-XL";
        var barcode = BarcodeWriter.CreateBarcode(productCode, BarcodeEncoding.Code128);
        
        // Define fonts for different purposes
        var titleFont = new Font("Arial", FontStyle.Bold, 14);
        var valueFont = new Font("Arial", FontStyle.Regular, 12);
        
        // Add product name above
        barcode.AddAnnotationTextAboveBarcode("Premium Widget XL", titleFont, Color.Black, 5);
        
        // Add product code below
        barcode.AddBarcodeValueTextBelowBarcode(valueFont, Color.DarkGray, 3);
        
        // Apply additional styling
        barcode.ResizeTo(250, 80)
               .SaveAsImage("product_label_annotated.png");
    }
}
Teal and beige QR code generated by IronBarcode containing ironsoftware.com URL

As an extension of the previous code snippet, we instantiate two new IronSoftware.Drawing.Font objects to serve as fonts for annotations both above and below the barcode. Only the Font Family is required to instantiate the font, though you can specify additional properties like size and style for more control.

  • AddAnnotationTextAboveBarcode: Adds custom annotation text above the barcode.
  • AddBarcodeValueTextBelowBarcode: Adds the barcode value below the barcode.

These two methods accept the same parameters: the IronSoftware.Drawing.Font objects, an IronSoftware.Drawing.Color object, and the amount of spacing between the barcode and the text. Additionally, the AddAnnotationTextAboveBarcode method requires a string for the annotation text, as it adds custom text above the barcode.

IronBarcode offers a wide range of customization options for styling barcodes. For applications requiring Unicode support in annotations, check our Writing Unicode Barcodes guide. To learn more about customizing QR codes, refer to "How to Customize and Add Logos to QR Codes". For exporting styled barcodes to different formats, explore our Create Barcode as HTML tutorial.

Frequently Asked Questions

How can I customize barcode colors using IronBarcode?

IronBarcode allows you to customize barcode colors by using the ChangeBarCodeColor() and ChangeBackgroundColor() methods. These methods enable adjusting both the barcode and background colors, which is particularly useful for branding and creating themed barcodes.

What method should I use to resize barcodes in IronBarcode?

To resize barcodes, you should use the ResizeTo() method provided by IronBarcode. This method allows you to specify new width and height dimensions in pixels, enabling lossless re-rendering while maintaining the barcode's quality.

When is the ResizeToMil method preferred?

The ResizeToMil method is preferred for 1D barcodes, particularly in industrial applications where precise measurements are essential. It uses mils (thousandths of an inch) for barcode element width, ensuring consistent readability across different scanners and conditions.

How can I add annotations to barcodes in IronBarcode?

IronBarcode provides the option to add annotations using methods like AddAnnotationTextAboveBarcode and AddBarcodeValueTextBelowBarcode. These allow you to include custom text above and the barcode value below the barcode, which is useful for product labeling and inventory management.

What are some supported barcode formats in IronBarcode?

IronBarcode supports a wide range of barcode formats including PDF417, Aztec, IntelligentMail, MaxiCode, and DataMatrix, among others. For a complete list of supported formats, you can refer to the Supported Barcode Formats documentation on the IronBarcode website.

Can I use IronBarcode to create QR codes with custom styles?

Yes, IronBarcode allows you to customize and style QR codes using similar methods available for other barcodes. You can change colors, add logos, and more, providing extensive styling capabilities for QR codes.

How does IronBarcode maintain barcode quality during resizing?

IronBarcode maintains barcode quality during resizing by triggering a lossless re-rendering process when using methods like ResizeTo(). This ensures the barcode remains high quality and readable after being resized.

Is there support for advanced color manipulation in IronBarcode?

Advanced color manipulation in IronBarcode is supported through integration with the IronDrawing library. This allows for precise control over barcode and background colors, which can be tailored to meet branding or thematic requirements.

How can IronBarcode assist with creating product labels?

IronBarcode can assist in creating product labels by allowing the addition of annotations, customizing barcode dimensions, and altering colors to match product branding. Methods like AddAnnotationTextAboveBarcode help include human-readable information on labels.

What font options are available for barcode annotations in IronBarcode?

For barcode annotations, IronBarcode provides options through IronSoftware.Drawing.Font, allowing you to customize font family, size, style, and color. This adds flexibility for styling annotations aligned with specific product or branding needs.

Ready to Get Started?

Nuget Downloads 2,422,100Version:2026.9just released

Get your FREE

30-day Trial Key instantly.

bullet_checkedNo credit card or account creation required
bullet_testTest in production
without watermarks
bullet_calendar30 days fully
functional product
bullet_support24/5 technical
support during trial
Get your free 30-day Trial Key instantly.
No credit card or account creation required
C# NuGet Library for PDF
Install with NuGet

Version: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. In Solution Explorer, right-click References, Manage NuGet Packages
  2. Select Browse and search "IronBarCode"
  3. Select the package and install
C# PDF DLL
Download DLL

Version: 2026.9

  1. Download and unzip IronBarCode to a location such as ~/Libs within your Solution directory
  2. In Visual Studio Solution Explorer, right click References. Select Browse, "IronBarCode.dll"

Licenses from $999

Key in blue circle

Get your free 30-day Trial Key instantly.

Your trial license will be sent to your email address

No limitations. 100% unlocked. No credit card.

bullet_checkedNo credit card or account creation requiredNo limitations. 100% unlocked. No credit card.
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
Book your free Live Demo
Booking Badge

Trusted by Millions of Engineers Worldwide

Iron Software's customer logos
Get Your No-Obligation Consult
Complete the form below or email sales@ironsoftware.com
Your details will always be kept confidential.
Trusted by Millions of Engineers Worldwide
Iron Software's customer logos
Get your free 30-day Trial Key instantly.
No credit card or account creation required