How to Read Multiple Barcodes at Once in C#
IronBarcode enables simultaneous reading of multiple barcodes from images and PDFs by setting ExpectMultipleBarcodes = true, streamlining data processing for logistics, retail, and inventory management applications. Whether building warehouse systems, retail point-of-sale applications, or document processing solutions, IronBarcode's advanced reading capabilities provide the reliability and performance you need.
Quickstart: Read All Barcodes from an Image Easily
This example shows how quickly you can use IronBarcode to scan an image for every barcode it contains. Just set ExpectMultipleBarcodes = true alongside the barcode types you want—no boilerplate, no hassle.
Get started making PDFs with NuGet now:
Install IronBarcode with NuGet Package Manager
Copy and run this code snippet.
var results = IronBarCode.BarcodeReader.Read("image.png", new IronBarCode.BarcodeReaderOptions { ExpectMultipleBarcodes = true, ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.AllOneDimensional });Deploy to test on your live environment
Minimal Workflow (5 steps)
- Download the C# library to read multiple barcodes
- Use the
Readmethod to extract barcode values from various image formats - Utilize the
ExpectMultipleBarcodesproperty to configure reading of single or multiple barcodes - Set the
ExpectMultipleBarcodesproperty to false to increase performance - Print out the barcode values
How Do I Read Multiple Barcodes from an Image?
By default, IronBarcode continuously scans a document to read multiple barcodes. However, there have been instances where only one barcode value is returned, even when multiple barcodes are present. To address this, customize the settings to enable reading multiple barcodes, as shown below. The ExpectMultipleBarcodes property exists in both BarcodeReaderOptions and PdfBarcodeReaderOptions classes, allowing you to use it for reading barcodes in both images and PDF documents.

:path=/static-assets/barcode/content-code-examples/how-to/read-multiple-barcodes-read-multiple-barcodes.csusing IronBarCode;
using System;
// Set the option to read multiple barcodes
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = true,
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
};
// Read barcode
var results = BarcodeReader.Read("testbc1.png", options);
foreach (var result in results)
{
Console.WriteLine(result.ToString());
}Setting ExpectMultipleBarcodes to true enables IronBarcode to scan the entire document for multiple barcodes and store them in the BarcodeResults variable. Using a foreach loop, you can easily access and print all barcode values to the console.
Advanced Multiple Barcode Reading Scenarios
When working with multiple barcodes, you might encounter scenarios that require additional configuration. Here's a comprehensive example demonstrating how to read multiple barcodes with different formats from a complex document:
using IronBarCode;
using System;
using System.Linq;
// Configure advanced options for mixed barcode types
BarcodeReaderOptions advancedOptions = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = true,
// Read both 1D and 2D barcodes
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional | BarcodeEncoding.QRCode | BarcodeEncoding.DataMatrix,
// Apply image correction filters for better accuracy
ImageFilters = new ImageFilterCollection() {
new SharpenFilter(),
new ContrastFilter()
},
// Set speed vs accuracy balance
Speed = ReadingSpeed.Balanced
};
// Read from various sources
var imageResults = BarcodeReader.Read("mixed-barcodes.jpg", advancedOptions);
var pdfResults = BarcodeReader.ReadPdf("document-with-barcodes.pdf", advancedOptions);
// Process results with error handling
foreach (var result in imageResults)
{
Console.WriteLine($"Barcode Type: {result.BarcodeType}");
Console.WriteLine($"Value: {result.Value}");
Console.WriteLine($"Confidence: {result.Confidence}%");
Console.WriteLine($"Page: {result.PageNumber}");
Console.WriteLine("---");
}using IronBarCode;
using System;
using System.Linq;
// Configure advanced options for mixed barcode types
BarcodeReaderOptions advancedOptions = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = true,
// Read both 1D and 2D barcodes
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional | BarcodeEncoding.QRCode | BarcodeEncoding.DataMatrix,
// Apply image correction filters for better accuracy
ImageFilters = new ImageFilterCollection() {
new SharpenFilter(),
new ContrastFilter()
},
// Set speed vs accuracy balance
Speed = ReadingSpeed.Balanced
};
// Read from various sources
var imageResults = BarcodeReader.Read("mixed-barcodes.jpg", advancedOptions);
var pdfResults = BarcodeReader.ReadPdf("document-with-barcodes.pdf", advancedOptions);
// Process results with error handling
foreach (var result in imageResults)
{
Console.WriteLine($"Barcode Type: {result.BarcodeType}");
Console.WriteLine($"Value: {result.Value}");
Console.WriteLine($"Confidence: {result.Confidence}%");
Console.WriteLine($"Page: {result.PageNumber}");
Console.WriteLine("---");
}This advanced example showcases several important features:
- Mixed barcode format support: Combining different barcode encoding types
- Image correction filters: Using image filters to improve reading accuracy
- Reading speed optimization: Balancing speed and accuracy with reading speed options
- Confidence scores: Accessing the confidence threshold for each detected barcode
How Can I Read a Single Barcode for Better Performance?
IronBarcode reads both single and multiple barcodes in images or PDFs. By default, the engine scans the entire document even if only one barcode exists. For increased performance when reading a single barcode, set ExpectMultipleBarcodes to false. This stops the engine from scanning the entire document after detecting the first barcode, resulting in faster barcode retrieval. The code below demonstrates this approach.

:path=/static-assets/barcode/content-code-examples/how-to/read-multiple-barcodes-read-single-barcode.csusing IronBarCode;
using System;
// Set the option to read single barcode
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = false,
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
};
// Read barcode
var results = BarcodeReader.Read("testbc1.png", options);
foreach (var result in results)
{
Console.WriteLine(result.ToString());
}In this example, we used the same image with multiple barcodes as before but set ExpectMultipleBarcodes to false. As a result, only the first barcode value is returned, and the scanning process stops once the first barcode is retrieved.
Optimizing Single Barcode Reading with Crop Regions
For even better performance when reading single barcodes, combine the ExpectMultipleBarcodes = false setting with crop region specifications. This technique is particularly useful when you know the approximate location of your barcode:
using IronBarCode;
using IronSoftware.Drawing;
// Define a crop region where the barcode is likely located
var cropRegion = new Rectangle(100, 100, 300, 200);
// Configure options for optimal single barcode reading
BarcodeReaderOptions optimizedOptions = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = false,
ExpectBarcodeTypes = BarcodeEncoding.Code128,
CropArea = cropRegion,
Speed = ReadingSpeed.Faster
};
// Read with optimized settings
var result = BarcodeReader.Read("product-label.png", optimizedOptions).FirstOrDefault();
if (result != null)
{
Console.WriteLine($"Barcode found: {result.Value}");
Console.WriteLine($"Read time: {result.ReadTime}ms");
}using IronBarCode;
using IronSoftware.Drawing;
// Define a crop region where the barcode is likely located
var cropRegion = new Rectangle(100, 100, 300, 200);
// Configure options for optimal single barcode reading
BarcodeReaderOptions optimizedOptions = new BarcodeReaderOptions()
{
ExpectMultipleBarcodes = false,
ExpectBarcodeTypes = BarcodeEncoding.Code128,
CropArea = cropRegion,
Speed = ReadingSpeed.Faster
};
// Read with optimized settings
var result = BarcodeReader.Read("product-label.png", optimizedOptions).FirstOrDefault();
if (result != null)
{
Console.WriteLine($"Barcode found: {result.Value}");
Console.WriteLine($"Read time: {result.ReadTime}ms");
}How Much Faster Is Single Barcode Reading?
Setting ExpectMultipleBarcodes to false greatly improves the efficiency of reading single barcodes. The performance gain is particularly noticeable when working with high-resolution images or when implementing asynchronous barcode reading in high-throughput applications.
Using the provided code snippet, here's a rough estimate of the performance difference between setting ExpectMultipleBarcodes to true and false on the same machine:
| ExpectMultipleBarcodes = true | ExpectMultipleBarcodes = false |
|---|---|
| 00.91 second | 00.10 second |
This represents approximately a 9x performance improvement when reading single barcodes. The actual performance gain varies based on:
- Image resolution and complexity
- Number of barcodes present in the image
- Selected barcode formats
- Applied image filters
- Hardware specifications
Best Practices for Multiple Barcode Reading
When implementing multiple barcode reading in production applications, consider these best practices:
Specify Expected Barcode Types: Instead of using
BarcodeEncoding.All, specify only the formats you expect. This significantly improves performance.Use Appropriate Image Formats: For best results, use high-contrast images. Learn more about creating optimal barcode images.
Handle Imperfect Barcodes: Real-world barcodes may be damaged or poorly printed. Use image correction techniques to improve reading success rates.
Stream Processing: For large batches, consider reading from streams to optimize memory usage.
- Error Handling: Always implement proper error handling for scenarios where barcodes cannot be read:
try
{
var results = BarcodeReader.Read("barcodes.png", new BarcodeReaderOptions
{
ExpectMultipleBarcodes = true
});
if (!results.Any())
{
Console.WriteLine("No barcodes found in the image");
}
else
{
Console.WriteLine($"Found {results.Count()} barcodes");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error reading barcodes: {ex.Message}");
// Log error for debugging
}try
{
var results = BarcodeReader.Read("barcodes.png", new BarcodeReaderOptions
{
ExpectMultipleBarcodes = true
});
if (!results.Any())
{
Console.WriteLine("No barcodes found in the image");
}
else
{
Console.WriteLine($"Found {results.Count()} barcodes");
}
}
catch (Exception ex)
{
Console.WriteLine($"Error reading barcodes: {ex.Message}");
// Log error for debugging
}By following these practices and utilizing IronBarcode's comprehensive features, you can build robust applications that efficiently handle multiple barcode reading scenarios across various industries and use cases.
Frequently Asked Questions
How can I read multiple barcodes from a single image in C#?
With IronBarcode, you can read multiple barcodes from a single image by setting ExpectMultipleBarcodes = true in the BarcodeReaderOptions. This enables IronBarcode to scan the entire document and return all found barcodes in a BarcodeResults collection that you can iterate through.
What's the quickest way to scan all barcodes in an image?
The fastest approach is using IronBarcode's Read method with ExpectMultipleBarcodes = true: var results = IronBarCode.BarcodeReader.Read("image.png", new IronBarCode.BarcodeReaderOptions { ExpectMultipleBarcodes = true }). This minimal code extracts all barcode values without complex configuration.
Can I read multiple barcodes from PDF documents as well as images?
Yes, IronBarcode supports reading multiple barcodes from both images and PDF documents. The ExpectMultipleBarcodes property is available in both BarcodeReaderOptions and PdfBarcodeReaderOptions classes, allowing you to configure multiple barcode reading for any document type.
What happens if I don't set ExpectMultipleBarcodes to true?
By default, IronBarcode continuously scans documents for multiple barcodes. However, in some cases, only one barcode value may be returned even when multiple barcodes exist. Setting ExpectMultipleBarcodes = true explicitly ensures IronBarcode scans and returns all barcodes in the document.
How do I access individual barcode values after reading multiple barcodes?
After reading multiple barcodes with IronBarcode, the results are stored in a BarcodeResults variable. You can easily access individual barcode values using a foreach loop to iterate through the collection and process each barcode's value, text, and format properties.
Is reading multiple barcodes suitable for retail and logistics applications?
Yes, IronBarcode's multiple barcode reading capability is ideal for retail point-of-sale systems, warehouse management, logistics tracking, and inventory management applications. It streamlines data processing by efficiently scanning all barcodes in shipping labels, product catalogs, or inventory sheets simultaneously.
Can I specify which barcode types to look for when reading multiple barcodes?
Yes, IronBarcode allows you to specify expected barcode types using the ExpectBarcodeTypes property. You can set it to scan for specific formats like AllOneDimensional, QRCode, or any combination of supported barcode types to optimize scanning performance.
Does setting ExpectMultipleBarcodes affect scanning performance?
Setting ExpectMultipleBarcodes = false can increase performance when you know only one barcode exists in the document. IronBarcode will stop scanning after finding the first barcode, making it faster for single-barcode scenarios while still providing the flexibility for multi-barcode reading when needed.






