How to Read Barcodes from Images Using C#
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.
Get started making PDFs with NuGet now:
Install IronBarcode with NuGet Package Manager
Copy and run this code snippet.
var results = IronBarCode.BarcodeReader.Read("path/to/image.png");Deploy to test on your live environment
Minimal Workflow (5 steps)

- Download C# library to read barcode from image
- Use the
Readmethod to read barcode values from various image formats - Utilize the BarcodeReaderOptions class to configure reading settings
- Specify barcode regions in the image with the CropArea property
- Specify barcode types to read by setting the ExpectBarcodeTypes property
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:
:path=/static-assets/barcode/content-code-examples/how-to/read-barcodes-from-images-1.csusing IronBarCode;
using System;
var myBarcode = BarcodeReader.Read(@"image_file_path.jpg"); //image file path
foreach (var item in myBarcode)
{
Console.WriteLine(item.ToString());
}Imports IronBarCode
Imports System
Private myBarcode = BarcodeReader.Read("image_file_path.jpg") 'image file path
For Each item In myBarcode
Console.WriteLine(item.ToString())
Next item

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, EAN18, 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
};// Example of setting CropArea
var cropArea = new IronSoftware.Drawing.Rectangle(x: 100, y: 100, width: 300, height: 300);
var options = new BarcodeReaderOptions()
{
CropArea = cropArea
};IRON VB CONVERTER ERROR developers@ironsoftware.comWhich 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
};// Example: Expect only QR codes and Code128
var options = new BarcodeReaderOptions()
{
ExpectBarcodeTypes = BarcodeEncoding.QRCode | BarcodeEncoding.Code128
};IRON VB CONVERTER ERROR developers@ironsoftware.comHere's a list of the barcode types with examples and explanations provided earlier.
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 MaxParallelThread 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.
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
Speedproperty. 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.Balancedis not successful in producing barcode values from the read, users may opt to useReadingSpeed.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. This will greatly reduce the reading performance of IronBarcode. 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,
// Enable Code39 extended mode if needed
UseCode39ExtendedMode = true,
// Set scan mode
ScanMode = BarcodeReaderScanMode.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($"Confidence: {barcode.Confidence}%");
Console.WriteLine($"Position: X={barcode.X}, Y={barcode.Y}");
Console.WriteLine("---");
}
}
else
{
Console.WriteLine("No barcodes found in the image.");
}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,
// Enable Code39 extended mode if needed
UseCode39ExtendedMode = true,
// Set scan mode
ScanMode = BarcodeReaderScanMode.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($"Confidence: {barcode.Confidence}%");
Console.WriteLine($"Position: X={barcode.X}, Y={barcode.Y}");
Console.WriteLine("---");
}
}
else
{
Console.WriteLine("No barcodes found in the image.");
}IRON VB CONVERTER ERROR developers@ironsoftware.comFrom 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
What image formats are supported for barcode reading in C#?
IronBarcode supports reading barcodes from multiple image formats including SVG (Scalable Vector Graphics), JPEG, PNG, GIF, TIFF (Tagged Image File Format), and BMP (Bitmap Image File). This comprehensive format support is powered by IronDrawing, enabling seamless barcode extraction from various image types.
How can I read a barcode from an image file with just one line of code?
With IronBarcode, you can read barcodes from images using a single line of code: `var results = IronBarCode.BarcodeReader.Read("path/to/image.png");`. This simple method call automatically detects and extracts barcode data from PNG, JPEG, GIF, BMP, and TIFF files without any complex setup.
Can I specify which types of barcodes to look for when reading images?
Yes, IronBarcode allows you to specify barcode types using the ExpectBarcodeTypes property in BarcodeReaderOptions. This targeted approach improves reading performance by focusing only on the barcode formats you expect to find in your images.
Is it possible to read barcodes from a specific region within an image?
Absolutely! IronBarcode provides the CropArea property that allows you to specify particular regions within an image where barcodes are located. This feature is especially useful for large images or when you know the approximate location of barcodes, significantly improving processing speed.
How do I configure advanced reading settings for better accuracy?
IronBarcode offers the BarcodeReaderOptions class to configure advanced reading settings. This includes options for customizing barcode detection sensitivity, image preprocessing, and other parameters that can improve accuracy when dealing with challenging images or specific barcode types.
What makes barcode reading from images simple for C# developers?
IronBarcode simplifies barcode reading by providing the BarcodeReader.Read() method that works out-of-the-box with multiple image formats. Developers only need to specify the file name or file path as a parameter, making it incredibly straightforward to integrate barcode reading functionality into any C# application.






