How to Read Multiple Barcodes at Once
Reading multiple barcodes simultaneously is crucial for various industries, including logistics, retail, healthcare, and inventory management, as it enables efficient data processing. With IronBarcode, you can easily achieve this capability, making it a powerful tool for streamlining operations and enhancing productivity.
Get started with IronBarcode
Start using IronBarcode in your project today with a free trial.
How to Read Multiple Barcodes at Once
- Download the C# library to read multiple barcodes
- Use the
Read
method to extract barcode values from various image formats - Utilize the ExpectMultipleBarcodes property to configure reading of single or multiple barcodes
- Set the ExpectMultipleBarcodes property to false to increase performance
- Print out the barcode values
Read Multiple Barcodes Example
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 in the image. To address this, users can customize the settings to enable reading multiple barcodes, as shown in the code snippet below. Please note that the ExpectMultipleBarcodes property exists in both the BarcodeReaderOptions and PdfBarcodeReaderOptions classes, allowing users to use it for reading barcodes in both images and PDF documents.
Sample Image

:path=/static-assets/barcode/content-code-examples/how-to/read-multiple-barcodes-read-multiple-barcodes.cs
using IronBarCode;
using System;
// Initialize Barcode reader options to read multiple barcodes
BarcodeReaderOptions options = new BarcodeReaderOptions
{
// Configure to expect multiple barcodes in the image being processed
ExpectMultipleBarcodes = true,
// Specify that we expect any one-dimensional barcode types (like Code128, UPC, etc.)
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional,
};
// Read barcodes from the specified image file "testbc1.png" using the configured options
BarcodeResult[] results = BarcodeReader.Read("testbc1.png", options);
// Iterate over each decoded barcode result
foreach (BarcodeResult result in results)
{
// Output the barcode content to the console
Console.WriteLine(result.ToString());
}
Imports IronBarCode
Imports System
' Initialize Barcode reader options to read multiple barcodes
Private options As New BarcodeReaderOptions With {
.ExpectMultipleBarcodes = True,
.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
}
' Read barcodes from the specified image file "testbc1.png" using the configured options
Private results() As BarcodeResult = BarcodeReader.Read("testbc1.png", options)
' Iterate over each decoded barcode result
For Each result As BarcodeResult In results
' Output the barcode content to the console
Console.WriteLine(result.ToString())
Next result
By setting ExpectMultipleBarcodes to true in the code snippet, IronBarcode scans the entire document for multiple barcodes and stores them in the BarcodeResults variable. Using a foreach loop, users can easily access and print all the barcode values to the console.
Reading Single Barcode Example
IronBarcode can read both single and multiple barcodes in an image or PDF. By default, the engine scans the entire document even if there is only one barcode. However, for increased performance when reading a single barcode, you can set ExpectMultipleBarcodes to false. This stops the engine from scanning the entire document after the first barcode is detected, resulting in faster barcode retrieval. The code snippet below demonstrates how to do this.
Sample Image

:path=/static-assets/barcode/content-code-examples/how-to/read-multiple-barcodes-read-single-barcode.cs
using IronBarCode;
using System;
// Entry point of the program
class Program
{
static void Main()
{
// Create options to configure the barcode reader
BarcodeReaderOptions options = new BarcodeReaderOptions
{
// Expect only one barcode per image
ExpectMultipleBarcodes = false,
// Specify the expected types of barcodes (one-dimensional barcodes in this case)
ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
};
// Read barcode from a specified image file with the given options
var results = BarcodeReader.Read("testbc1.png", options);
// Check if results are not null to avoid possible null reference exceptions
if (results != null)
{
// Iterate over all read results and print each barcode as a string
foreach (var result in results)
{
// Print out the barcode value and type for better debugging or display
Console.WriteLine($"Barcode Value: {result.Text}, Barcode Type: {result.Encoding}");
}
}
else
{
// Inform the user that no barcodes were found
Console.WriteLine("No barcodes were found in the image.");
}
}
}
Imports IronBarCode
Imports System
' Entry point of the program
Friend Class Program
Shared Sub Main()
' Create options to configure the barcode reader
Dim options As New BarcodeReaderOptions With {
.ExpectMultipleBarcodes = False,
.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
}
' Read barcode from a specified image file with the given options
Dim results = BarcodeReader.Read("testbc1.png", options)
' Check if results are not null to avoid possible null reference exceptions
If results IsNot Nothing Then
' Iterate over all read results and print each barcode as a string
For Each result In results
' Print out the barcode value and type for better debugging or display
Console.WriteLine($"Barcode Value: {result.Text}, Barcode Type: {result.Encoding}")
Next result
Else
' Inform the user that no barcodes were found
Console.WriteLine("No barcodes were found in the image.")
End If
End Sub
End Class
In the code snippet above, we used the same image with multiple barcodes as before, but this time, we 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.
Performance Comparison
Setting ExpectMultipleBarcodes to false can greatly improve the efficiency of reading single barcodes in the image.
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 |
Frequently Asked Questions
What is IronBarcode?
IronBarcode is a library for reading and writing barcodes in .NET applications, enabling efficient data processing in various industries.
How can I read multiple barcodes using IronBarcode?
To read multiple barcodes, set the ExpectMultipleBarcodes property to true in the BarcodeReaderOptions or PdfBarcodeReaderOptions classes and use the Read method.
Why is reading multiple barcodes simultaneously important?
Reading multiple barcodes simultaneously is crucial for efficient data processing in industries such as logistics, retail, and healthcare.
How do I optimize IronBarcode for reading a single barcode?
Set the ExpectMultipleBarcodes property to false to stop scanning after detecting the first barcode, improving performance.
Can IronBarcode read barcodes from PDF documents?
Yes, IronBarcode can read barcodes from both images and PDF documents by configuring the appropriate reader options.
What are the performance benefits of setting ExpectMultipleBarcodes to false?
Setting ExpectMultipleBarcodes to false greatly improves performance by reducing the time needed to retrieve a single barcode.
What are the steps to read multiple barcodes using IronBarcode?
Download the C# library, configure the ExpectMultipleBarcodes property, use the Read method, and print the barcode values.
What should I do if only one barcode is returned in an image with multiple barcodes?
Ensure that the ExpectMultipleBarcodes property is set to true to enable reading all barcodes present in the image.