IRONSOFTWAREHOME

How to Create Barcode Images in C# with IronBarcode

Hairil Hasyimi Bin Omar
Hairil Hasyimi Bin Omar
Updated: August 2, 2026

IronBarcode enables .NET developers to generate barcode and QR code images in C# with a single line of code, supporting multiple formats and image types. Build inventory management systems, retail applications, or document processing solutions with a robust API that creates professional-quality barcodes for reliable scanning across all major readers.

Quickstart: Create and Save a Code128 Barcode in One Line

Use IronBarcode's one-line API to create a Code128 barcode from a string and save it as a PNG image. Get started immediately - supply the data, choose the encoding and size, and write your image file.

  1. 1Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. 2Copy and run this code snippet.

    IronBarCode.BarcodeWriter.CreateBarcode("Sample123", BarcodeEncoding.Code128, 250, 100).SaveAsPng("Barcode.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 Generate Barcodes and Save as Image Files?

Besides reading barcodes, IronBarcode allows users to write barcodes with minimal coding. Call the CreateBarcode() method from the BarcodeWriter class, specifying the barcode value, type, width, and height in the method parameters. This outputs a GeneratedBarcode object, which can be saved as an image file using the SaveAs() method.

What Types of Data Can I Use for Barcode Values?

The BarcodeWriter.CreateBarcode() method accepts multiple data types for barcode values: byte[] array, MemoryStream, and string. String lengths and accepted characters vary by barcode type - see our API documentation for details. Code128 supports the full ASCII character set, while UPC-A requires exactly 12 numeric digits. For binary data, use byte[] array to encode complex data structures.

Which Barcode Encoding Types Are Supported?

IronBarcode supports numerous barcode formats - see our Supported Barcode Formats article for the complete list. Popular formats include:

  • Linear/1D Barcodes: Code128, Code39, UPC-A, UPC-E, EAN-8, EAN-13
  • 2D Barcodes: QR Code, Data Matrix, PDF417, Aztec
  • Specialized Formats: MaxiCode for shipping, Databar for retail

Each format serves specific uses. Code128 handles general alphanumeric data well, while QR codes offer superior error correction for mobile scanning.

How Do Width and Height Settings Affect My Barcode?

Set the output barcode image dimensions in pixels. Default measurements are 250 px for both. Some barcode types (QR, PDF417) require specific dimensions for compliance. When input dimensions don't match requirements, the barcode generates at compliant dimensions with whitespace filling remaining space. Too-small dimensions throw an exception.

For optimal scanning:

  • Linear barcodes: Maintain width significantly greater than height
  • 2D barcodes: Use square dimensions for QR codes (e.g., 250x250)
  • Print quality: Higher pixel dimensions improve print quality at larger physical sizes

What Image Formats Can I Export Barcodes To?

The GeneratedBarcode object from BarcodeWriter.CreateBarcode() saves to various image formats using specific SaveAs() methods:

  • SaveAsGif(): Saves as GIF image file
  • SaveAsJpeg(): Saves as JPEG image file
  • SaveAsPng(): Saves as PNG image file (recommended for web)
  • SaveAsTiff(): Saves as TIFF image file (ideal for archival/printing)
  • SaveAsWindowsBitmap(): Saves as BMP image file
  • SaveAsImage(): General method - specify format extension in file path

Additionally, export barcodes as streams for in-memory processing or create barcodes as PDF documents for document integration.

How Do I Generate a Barcode and Save It As an Image File?

Use BarcodeWriter.CreateBarcode() to create a Code128 barcode and save it as a JPEG image:

using IronBarCode;

// Create a basic barcode
BarcodeWriter.CreateBarcode("IronBarcode123", BarcodeEncoding.Code128, 200, 100).SaveAsJpeg("OneDBarcode.jpeg");

// Create a barcode with custom options
var myBarcode = BarcodeWriter.CreateBarcode("PRODUCT-12345", BarcodeEncoding.Code128, 300, 150);

// Apply styling
myBarcode.AddBarcodeValueTextBelowBarcode();
myBarcode.SetMargins(10);

// Save in multiple formats
myBarcode.SaveAsJpeg("product-barcode.jpg");
myBarcode.SaveAsPng("product-barcode.png");
Generated one-dimensional barcode with black vertical bars showing example output from barcode creation code

For advanced styling options, see our guide on customizing barcode styles.

How Do I Generate QR Codes and Save as Image Files?

QR codes, classified as two-dimensional barcodes, are fully supported by IronBarcode. Their versatility, cosmetic appeal, and customizable features have driven widespread adoption from restaurant menus to payment systems.

Creating QR codes requires different methods due to their complexity. Call the CreateQrCode() method from the QRCodeWriter class, which accepts 4 arguments: the barcode value, output QR code size, QRCodeWriter.QrErrorCorrectionLevel enum field, and QRVersion.

What Data Types Can I Use for QR Code Values?

QRCodeWriter.CreateQrCode() accepts numerical, alphabetical, or alphanumeric values as byte[] array, MemoryStream, or System.String types. QR codes excel at storing:

  • URLs: Direct users to websites or landing pages
  • Text: Store up to 4,296 alphanumeric characters
  • Binary data: Encode files or complex data structures
  • Structured data: vCards, WiFi credentials, or payment information

For Unicode support and international characters, see our writing Unicode barcodes tutorial.

How Do I Set the QR Code Size?

Specify QR code size directly as Int32 type in pixels (px). Default size is 500 px. Consider these factors:

  • Display medium: Screen displays typically need 200-400px
  • Print applications: Use 600px or higher for quality printing
  • Scanning distance: Larger codes scan better from greater distances

What Is QR Error Correction Level and Why Does It Matter?

QRErrorCorrectionLevel determines fault tolerance, with four levels: Highest, High, Medium, and Low. Higher correction levels create more complex QR codes that resist reading errors even when damaged or partially obscured.

QRErrorCorrectionLevel.Highest

Generates the most complex QR code with 30% error correction. Supports logo stamping or image graphics. Ideal for customizing QR codes with logos.

QR code generated with highest error correction level showing dense black and white pattern with positioning squares

QRErrorCorrectionLevel.High

Applies 25% error correction. Less complex than Highest level. Balances durability with data capacity.

QR code example showing high error correction level with dense data pattern and standard positioning elements

QRErrorCorrectionLevel.Medium

Applies 15% error correction. Produces QR codes faster but with more error susceptibility. Suitable for most business applications with clear printing.

Generated QR code example showing black and white data matrix with corner position markers

QRErrorCorrectionLevel.Low

Applies 7% error correction, creating the least complex QR code. Use when maximum data capacity is required with optimal scanning conditions.

Sample QR code generated with low error correction level showing standard black and white module pattern

When Should I Use Different QR Versions?

QR Version (1-40) determines symbol complexity and data capacity. Higher versions produce more complex codes storing more data. Setting version too low causes issues encoding larger data amounts. Version 0 automatically assigns the appropriate version based on encoded value. See QR Version for more information.

How Do I Create a QR Code Image with Specific Settings?

Use QRCodeWriter.CreateQrCode() to write a QR code and save it as an image:

using IronBarCode;

// Basic QR code creation
QRCodeWriter.CreateQrCode("IronBarcode1234", 250, QRCodeWriter.QrErrorCorrectionLevel.Medium, qrVersion: 0).SaveAsJpeg("QRMedium.jpeg");

// Advanced QR code with logo and custom styling
var qrCode = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com", new QRCodeLogo("logo.png"), 500);

// Apply styling
qrCode.ChangeBarCodeColor(System.Drawing.Color.DarkBlue);

// Save in multiple formats
qrCode.SaveAsPng("styled-qr.png");
qrCode.SaveAsPdf("styled-qr.pdf");
C#
QR code example showing medium error correction level with standard finder patterns and data encoding structure

The code encodes an alphanumeric value at 250 pixels with medium error correction. Version 0 lets the program select the appropriate QR code version. SaveAsJpeg() accepts the filename with JPEG extension.

Best Practices for Barcode Image Generation

For production applications:

  1. Choose the right format: PNG for web, TIFF for archival, JPEG for general use
  2. Test scanning: Verify barcodes with multiple scanning devices
  3. Apply proper margins: Use barcode margin settings for reliable scanning
  4. Consider performance: Explore async and multithreading options for high-volume generation

For additional examples and techniques, visit our C# Barcode Image Generator tutorial.

Frequently Asked Questions

What is the simplest way to create a barcode image in C# using IronBarcode?

IronBarcode provides a one-line API to create barcode images. You can use `BarcodeWriter.CreateBarcode()` method to generate a `Code128` barcode from a string with specified dimensions and save it as a PNG image.

What are some popular barcode formats supported by IronBarcode?

IronBarcode supports various barcode formats such as `Code128`, `Code39`, `UPC-A`, `QR Code`, `Data Matrix`, and many more. Each format is suitable for specific use cases like retail, inventory management, or document processing.

How can I save a generated barcode image to different file formats using IronBarcode?

The `GeneratedBarcode` object in IronBarcode can be saved in several formats, including PNG, JPEG, GIF, BMP, and TIFF. Use methods like `SaveAsPng()`, `SaveAsJpeg()`, or `SaveAsTiff()` to save your barcode image in the desired format.

Can IronBarcode generate QR codes with specific error correction levels?

Yes, IronBarcode allows setting QR error correction levels ranging from Low to Highest. This feature ensures your QR codes remain scannable even if damaged or partially obscured.

What types of data can be encoded as barcode values in IronBarcode?

IronBarcode can encode data types including `byte[] array`, `MemoryStream`, and `string`. Different barcode formats have specific requirements for data types and character sets.

How does IronBarcode ensure compliance with barcode dimension requirements?

IronBarcode allows you to specify width and height in pixels for your barcode images. If specified dimensions do not comply with format requirements, IronBarcode automatically adjusts them to include necessary whitespace.

What are the capabilities of QR codes generated using IronBarcode?

The QR codes generated by IronBarcode can store a variety of data types such as URLs, text, binary data, and structured data like vCards or WiFi credentials. They offer flexibility and customization for diverse applications.

How can I customize the appearance of barcode images with IronBarcode?

IronBarcode provides customization options like changing colors, adjusting margins, and applying text below the barcode. Additionally, you can embed logos within QR codes for branding purposes.

Why is it important to choose the correct image format for barcode generation?

Choosing the right image format ensures optimal quality for specific uses. For instance, PNG is best for web display, TIFF for archival purposes, and JPEG for general use. Proper format selection promotes reliable scanning and data integrity.

What best practices should I follow when generating barcode images with IronBarcode?

Best practices include choosing the right image format, testing barcodes with multiple scanners, setting proper margins, and considering performance needs by leveraging async and multithreading techniques for high-volume generation.

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