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.

First Step:
green arrow pointer



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

Image to be read
:path=/static-assets/barcode/content-code-examples/how-to/read-multiple-barcodes-read-multiple-barcodes.cs
using 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());
}
Imports IronBarCode
Imports System

' Set the option to read multiple barcodes
Private options As New BarcodeReaderOptions() With {
	.ExpectMultipleBarcodes = True,
	.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
}

' Read barcode
Private results = BarcodeReader.Read("testbc1.png", options)

For Each result In results
	Console.WriteLine(result.ToString())
Next result
$vbLabelText   $csharpLabel

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

Image to be read
:path=/static-assets/barcode/content-code-examples/how-to/read-multiple-barcodes-read-single-barcode.cs
using 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());
}
Imports IronBarCode
Imports System

' Set the option to read single barcode
Private options As New BarcodeReaderOptions() With {
	.ExpectMultipleBarcodes = False,
	.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional
}

' Read barcode
Private results = BarcodeReader.Read("testbc1.png", options)

For Each result In results
	Console.WriteLine(result.ToString())
Next result
$vbLabelText   $csharpLabel

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

How do I read multiple barcodes in an image using C#?

To read multiple barcodes in an image using C#, you can utilize IronBarcode's Read method with the ExpectMultipleBarcodes property set to true within the BarcodeReaderOptions or PdfBarcodeReaderOptions classes.

What is the benefit of setting ExpectMultipleBarcodes to true in IronBarcode?

Setting ExpectMultipleBarcodes to true allows IronBarcode to scan for and read all barcodes present in an image, which is essential for industries that require processing multiple barcodes simultaneously for data efficiency.

Can I improve performance when reading a single barcode?

Yes, you can improve performance by setting ExpectMultipleBarcodes to false in IronBarcode. This stops the scanning process after the first barcode is detected, resulting in faster retrieval times.

How can I read barcodes from PDF documents in C#?

IronBarcode provides functionality to read barcodes from PDF documents using the Read method and configuring the appropriate options in PdfBarcodeReaderOptions.

What should I do if only one barcode is detected when multiple are present?

Ensure that the ExpectMultipleBarcodes property is set to true in IronBarcode to enable the detection and reading of all barcodes present in the image or PDF.

How do I configure IronBarcode to read barcodes from various image formats?

To configure IronBarcode for reading barcodes from various image formats, you should use the Read method and set the ExpectMultipleBarcodes property in the BarcodeReaderOptions class.

What is the performance difference when using ExpectMultipleBarcodes set to true versus false?

The performance difference is significant; setting ExpectMultipleBarcodes to false reduces processing time, as it stops scanning after detecting the first barcode, whereas setting it to true scans for all barcodes, which takes longer.

Is there a C# library for reading multiple barcodes efficiently?

Yes, IronBarcode is a C# library that allows efficient reading of multiple barcodes from images and PDF documents, providing tools to improve performance and streamline data processing.

Hairil Hasyimi Bin Omar
Software Engineer
Like all great engineers, Hairil is an avid learner. He’s refining his knowledge of C#, Python, and Java, using that knowledge to add value to team members across Iron Software. Hairil joined the Iron Software team from Universiti Teknologi MARA in Malaysia, where he graduated with a Bachelor's degree ...Read More