IRONSOFTWAREHOME

How to Read Barcodes from Images Using C#

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

IronBarcode reads barcodes from images in C# with a single line of code using BarcodeReader.Read(), supporting multiple image formats including PNG, JPEG, GIF, BMP, TIFF, and SVG, with customizable options for improved performance and accuracy.

One of the key features of IronBarcode is its ability to read barcodes out-of-the-box in multiple image formats. The following image formats are currently supported by IronBarcode:

  • Scalable Vector Graphics (SVG)
  • Joint Photographic Experts Group (JPEG)
  • Portable Network Graphics (PNG)
  • Graphics Interchange Format (GIF)
  • Tagged Image File Format (TIFF)
  • Bitmap Image File (BMP)

This is made possible with the help of our open source library, IronDrawing. For a complete list of supported barcode formats, including both 1D and 2D types, check our comprehensive documentation.

Quickstart: Read Barcodes from an Image in Seconds

With just one simple call to IronBarCode.BarcodeReader.Read(), you can extract barcode data straight from image file formats like PNG, JPEG, GIF, BMP, and TIFF. Get started instantly - no complex setup, just instant results.

  1. 1Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. 2Copy and run this code snippet.

    var results = IronBarCode.BarcodeReader.Read("path/to/image.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 Read Barcodes Directly From Images?

Here's how to use IronBarcode for barcode reading. For a comprehensive tutorial on reading barcodes in C# / .NET, including advanced techniques for PDF processing and batch operations, visit our detailed guide:

using IronBarCode;
using System;

var myBarcode = BarcodeReader.Read(@"image_file_path.jpg"); //image file path

foreach (var item in myBarcode)
{
    Console.WriteLine(item.ToString());
}
Sample QR code with finder patterns for testing barcode reading from images
Sample test QR code
Sample barcode with black vertical lines on white background for testing image-based barcode reading
Sample test barcode
Want to know what are the barcode values in the samples? Try it with the code snippet!

To use IronBarcode, the first thing you have to do is to install the IronBarcode library via Microsoft Visual Studio NuGet package manager into your project, as shown in the picture below. This will allow you to access IronBarcode's BarcodeReader.Read() method to directly read barcode images.

IronBarcode offers simplicity by allowing users to only use BarcodeReader.Read() to read an image file that has already been included inside the project by specifying the file name string, OR file path string as the parameter for the method. Best practice is to use the verbatim string literal, "@" when specifying a file path in the method to avoid adding multiple escape characters "\" in the file path string.

Attach the Values() method at the end of the BarcodeReader.Read() method call to get the barcode value as a System.String[] object.

To output the result to the console, you can use a foreach loop to iterate over the values stored in the string[] array and inside the loop block, call the Console.WriteLine() method with the iterator variable as the parameter.

IronBarcode is capable of reading 1-Dimensional barcode formats (Codabar, Code128, Code39, Code93, EAN13, EAN8, ITF, MSI, UPCA, UPCE) as well as 2-Dimensional barcode formats (Aztec, DataMatrix, QRCode) in various image formats.

How Can I Configure Barcode Reader Options for Better Performance?

Finding barcode reading too slow? Is the barcode too small in the picture, making IronBarcode unable to read it? Want to read only certain areas of an image? Want to read only certain types of barcodes in an image with a mixture of barcodes? Want to improve overall reading performance?

BarcodeReaderOptions allows users to tweak or adjust the behavior of the barcode reader to address all these issues. For detailed examples on setting barcode reader options, check our comprehensive guide. The following sections discuss all the adjustable properties available in BarcodeReaderOptions one by one.

How Do I Specify Which Area of the Image to Read?

CropArea is a property of type IronSoftware.Drawing.CropRectangle available in BarcodeReaderOptions that allows users to specify the area in an image IronBarcode should read. This helps improve reading performance, since the barcode reader does not scan through the entire image for barcodes, as well as improving reading accuracy since the area of read has been specified. Learn more about how to specify crop regions for optimal performance.

To set the CropArea property, simply instantiate a new Rectangle type object and specify the rectangle coordinates, width, and length of the rectangle as arguments. The measurement unit accepted is pixels (px).

// Example of setting CropArea
var cropArea = new IronSoftware.Drawing.Rectangle(x: 100, y: 100, width: 300, height: 300);
var options = new BarcodeReaderOptions()
{
    CropArea = cropArea
};

Which Barcode Types Should I Specify for Faster Reading?

By default, all supported barcodes in IronBarcode will be scanned in an image. However, if the user knows what types of barcodes are available or wants to be read in an image, setting this property to read only certain types of barcodes will greatly increase reading performance and accuracy since the barcode reader does not need to iterate through collections of barcodes to interpret and read a barcode.

To use this property, simply set the ExpectBarcodeTypes to one of the fields of the BarcodeEncoding enum. Below are examples of every barcode type supported by IronBarcode.

// Example: Expect only QR codes and Code128
var options = new BarcodeReaderOptions()
{
    ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128
};

When Should I Disable Multiple Barcode Reading?

IronBarcode will scan all barcodes available in an image by default, which includes scanning the whole image file and adding the read barcode values into the string array. However, if users do not wish to read multiple barcodes in an image file, users can set this property to false, which will make the barcode reader stop scanning once a barcode value has been found. This will again, improve the performance and reading speed of IronBarcode. For more information on reading multiple barcodes, see our dedicated guide.

How Do Image Filters Improve Barcode Recognition?

One of the properties that can be added in BarcodeReaderOptions is a collection of image filters. Image filters are important for preprocessing the raw image fed to IronBarcode. To apply image filters inside the BarcodeReaderOptions, users must first initiate and specify the ImageFilter collection to be used. For comprehensive guidance on image correction techniques, including filter applications, visit our tutorial.

How Can I Optimize Threading for Better Performance?

IronBarcode allows users to enable and tweak the amount of parallel threads execution, which in turn will improve the speed and efficiency of the process. Parallel threads mean execution of multiple threads simultaneously on different processor cores. The default amount for the MaxParallelThreads property in IronBarcode is 4. Users can adjust them based on the capabilities and amount of resources their machines have.

Should I Enable Multithreaded Processing?

This property enables IronBarcode to read multiple images in parallel. The default for #Multithreaded is true, hence the multiple threads will be managed automatically to improve performance for batch barcode reading tasks.

Why Should I Remove False Positive Readings?

This property removes any false-positive barcode reads. False-positive barcode reads simply mean a false read of barcode values, but identified as valid. This can happen due to errors in the sequencing process or errors in the barcode labeling or preparation process. Therefore, setting RemoveFalsePositive as true will remove the false-positive barcode readings, thus improving barcode reading accuracy. However, if users opt for performance at the cost of accuracy, setting this property to false would help. The default value for this property is true.

How Does MinScanLines Affect Detection Accuracy?

MinScanLines sets the minimum number of scan lines that must agree on a barcode result for it to be considered valid. The default is 2. Increasing this value reduces false positives but may prevent detection of thin or low-quality barcodes. Lowering it to 1 increases sensitivity for difficult barcodes at the risk of introducing noise.

What Scan Modes Are Available for Different Use Cases?

Define how IronBarcode scans and detects barcodes in an image.

  • Auto: Reads barcodes with automatic image pre-processing and the most optimal reader options configured. Recommended for best results and performance.
  • OnlyDetectionModel: Scans the image for barcodes and returns their positions as an array of IronSoftware.Drawing.PointF. This mode does not read the detected barcodes; it only returns the positions of each barcode.
  • MachineLearningScan: Scans the image for barcodes with machine learning detection and reads them.
  • OnlyBasicScan: Reads barcodes without machine learning detection, automatic image pre-processing, or reader option configuration. This option can be used with IronBarCode.Slim alone.

How Do Reading Speed Settings Affect Accuracy?

As the name suggests, the Speed property enables users to further optimize the performance of the IronBarcode reader. Similar to the RemoveFalsePositive property, adjusting this property improves performance at the cost of accuracy. For an in-depth look at reading speed options, including performance benchmarks, see our detailed guide. It accepts the ReadingSpeed enum, which has 4 levels as shown below:

  • Faster: Enables the fastest barcode reading but reduces accuracy. The process skips image preprocessing, often resulting in empty barcode results. Use this setting only if the input image is sharp and clear.
  • Balanced: This setting is recommended for the Speed property. It sets a balance between accuracy and read performance by attempting to apply light processing to the image to clarify the barcode area and make it stand out for the barcode reader to detect. Most of the time, this setting is enough for IronBarcode to read a barcode image and produce accurate output.
  • Detailed: For cases where using the setting ReadingSpeed.Balanced is not successful in producing barcode values from the read, users may opt to use ReadingSpeed.Detailed. IronBarcode will perform medium processing on the image to clarify the barcode area further and clearer for the barcode reader to detect the barcode. This setting is very useful to detect a small or less sharp barcode image.
  • ExtremeDetail: This setting is the least recommended due to its CPU-intensive process. Heavy processing will be performed on the barcode image in order for the reader to read the barcodes. Users are advised to do image preprocessing/applying filters on the image before opting for this setting.

When Should I Use Code39 Extended Mode?

This setting allows Code39 type barcodes to be read and interpreted with extended mode whereby the full ASCII Character Set will be applied. Setting UseCode39ExtendedMode to true will enable a more accurate reading of Code39 barcodes.

How Do I Implement Advanced Barcode Reading with Custom Options?

Now that we have learned all the options that can be tweaked by users, be it to increase performance or accuracy, here's how to apply them in code. The code snippet below demonstrates comprehensive usage of BarcodeReaderOptions:

using IronBarCode;
using IronSoftware.Drawing;
using System;
using System.Linq;

// Create custom reader options
var options = new BarcodeReaderOptions()
{
    // Specify expected barcode types for better performance
    ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128 | BarcodeEncoding.Code39,
    
    // Define specific area to scan (x, y, width, height in pixels)
    CropArea = new Rectangle(100, 100, 500, 400),
    
    // Set reading speed to balance accuracy and performance
    Speed = ReadingSpeed.Balanced,
    
    // Enable multithreading for better performance
    Multithreaded = true,
    MaxParallelThreads = 4,
    
    // Remove false positives for accuracy
    RemoveFalsePositive = true,

    // Minimum scan lines that must agree for a valid result (default 2)
    MinScanLines = 1,

    // Enable Code39 extended mode if needed
    UseCode39ExtendedMode = true,
    
    // Set scan mode
    ScanMode = BarcodeScanMode.Auto,
    
    // Add image filters for better recognition
    ImageFilters = new ImageFilterCollection() { 
        new SharpenFilter(),
        new InvertFilter(),
        new ContrastFilter()
    }
};

// Read barcodes with custom options
var results = BarcodeReader.Read(@"C:\path\to\your\barcode-image.png", options);

// Process results
if (results.Any())
{
    foreach (var barcode in results)
    {
        Console.WriteLine($"Barcode Type: {barcode.BarcodeType}");
        Console.WriteLine($"Value: {barcode.Value}");
        Console.WriteLine($"Position: {string.Join(", ", barcode.Points.Select(p => $"({p.X}, {p.Y})"))}");
        Console.WriteLine("---");
    }
}
else
{
    Console.WriteLine("No barcodes found in the image.");
}
C#

From the code snippet, we see that to use BarcodeReaderOptions we have to first initialize it, then determine and adjust the properties of the BarcodeReaderOptions according to the properties stated above. The initialized BarcodeReaderOptions can then be used as an argument in the BarcodeReader.Read() method along with the image file. This will apply all the settings in BarcodeReaderOptions when reading a barcode from the image.

If you encounter issues where your barcode is not recognized, our troubleshooting guide provides solutions for common problems and tips to enhance barcode scanning accuracy.

Frequently Asked Questions

How can I read barcodes from images using IronBarcode in C#?

You can read barcodes from images in C# with IronBarcode by using the `BarcodeReader.Read()` method. This method simplifies barcode reading with a single line of code and supports various image formats such as PNG, JPEG, GIF, BMP, and TIFF.

What image formats does IronBarcode support for barcode reading?

IronBarcode supports multiple image formats for barcode reading, including PNG, JPEG, GIF, BMP, TIFF, and SVG.

How do I customize the barcode reading options in IronBarcode?

You can customize barcode reading options in IronBarcode using the `BarcodeReaderOptions` class. It allows you to configure settings like `CropArea`, `ExpectBarcodeTypes`, `Speed`, and more to improve performance and accuracy.

Can IronBarcode read both 1D and 2D barcodes?

Yes, IronBarcode can read both 1D and 2D barcodes. Supported formats include Codabar, Code128, QRCode, DataMatrix, and more.

What is the purpose of the `CropArea` property in IronBarcode?

The `CropArea` property in IronBarcode is used to specify the specific area of an image where barcodes should be read. This helps enhance reading performance and accuracy by focusing on a defined region.

How can I increase the reading speed of barcodes with IronBarcode?

You can increase the barcode reading speed in IronBarcode by adjusting the `Speed` property in `BarcodeReaderOptions`. This allows you to balance performance and accuracy depending on your needs.

What are the benefits of using multithreading in IronBarcode?

Multithreading in IronBarcode allows multiple barcodes to be processed simultaneously, improving the speed and efficiency of barcode reading, especially in batch processing tasks.

How do image filters improve barcode recognition in IronBarcode?

Image filters in IronBarcode enhance preprocessing by improving the clarity of barcode images. Filters like the `SharpenFilter` and `ContrastFilter` help optimize image quality for better recognition.

What is the `MinScanLines` property used for in IronBarcode?

The `MinScanLines` property sets the minimum number of scan lines that must agree on a barcode result for it to be considered valid, reducing false positives while ensuring detection accuracy.

How do I handle multiple barcode types with IronBarcode?

In IronBarcode, you can specify which barcode types to read by setting the `ExpectBarcodeTypes` property in `BarcodeReaderOptions`, which improves performance by focusing on specific barcode types.

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