Cómo Leer Múltiples Códigos de Barras a la Vez en C#

How to Read Multiple Barcodes at Once

This article was translated from English: Does it need improvement?
Translated
View the article in English

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.

Quickstart: Read All Barcodes from an Image Easily

This example shows how quickly you can use IronBarcode to scan an image for every barcode contained within it. Just set ExpectMultipleBarcodes = true alongside the barcode types you want — no boilerplate, no hassle.

Nuget IconGet started making PDFs with NuGet now:

  1. Install IronBarcode with NuGet Package Manager

    PM > Install-Package BarCode

  2. Copy and run this code snippet.

    var results = IronBarCode.BarcodeReader.Read("image.png", new IronBarCode.BarcodeReaderOptions { ExpectMultipleBarcodes = true, ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.AllOneDimensional });
  3. Deploy to test on your live environment

    Start using IronBarcode in your project today with a free trial
    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

Preguntas Frecuentes

¿Cómo leo varios códigos de barras en una imagen usando C#?

Para leer varios códigos de barras en una imagen usando C#, puedes utilizar el método Read de IronBarcode con la propiedad ExpectMultipleBarcodes configurada en true dentro de las clases BarcodeReaderOptions o PdfBarcodeReaderOptions.

¿Cuál es el beneficio de configurar ExpectMultipleBarcodes en true en IronBarcode?

Configurar ExpectMultipleBarcodes en true permite a IronBarcode escanear y leer todos los códigos de barras presentes en una imagen, lo cual es esencial para las industrias que requieren procesar múltiples códigos de barras simultáneamente para mayor eficiencia de datos.

¿Puedo mejorar el rendimiento al leer un solo código de barras?

Sí, puedes mejorar el rendimiento configurando ExpectMultipleBarcodes en false en IronBarcode. Esto detiene el proceso de escaneo después de detectar el primer código de barras, resultando en tiempos de recuperación más rápidos.

¿Cómo puedo leer códigos de barras de documentos PDF en C#?

IronBarcode proporciona funcionalidad para leer códigos de barras de documentos PDF usando el método Read y configurando las opciones apropiadas en PdfBarcodeReaderOptions.

¿Qué debo hacer si solo se detecta un código de barras cuando hay varios presentes?

Asegúrate de que la propiedad ExpectMultipleBarcodes esté configurada en true en IronBarcode para habilitar la detección y lectura de todos los códigos de barras presentes en la imagen o PDF.

¿Cómo configuro IronBarcode para leer códigos de barras de varios formatos de imagen?

Para configurar IronBarcode para leer códigos de barras de varios formatos de imagen, debes usar el método Read y configurar la propiedad ExpectMultipleBarcodes en la clase BarcodeReaderOptions.

¿Cuál es la diferencia de rendimiento cuando se usa ExpectMultipleBarcodes configurado en true versus false?

La diferencia de rendimiento es significativa; configurar ExpectMultipleBarcodes en false reduce el tiempo de procesamiento, ya que detiene el escaneo después de detectar el primer código de barras, mientras que configurarlo en true escanea todos los códigos de barras, lo que toma más tiempo.

¿Existe una biblioteca de C# para leer múltiples códigos de barras eficientemente?

Sí, IronBarcode es una biblioteca de C# que permite la lectura eficiente de múltiples códigos de barras de imágenes y documentos PDF, proporcionando herramientas para mejorar el rendimiento y agilizar el procesamiento de datos.

Hairil Hasyimi Bin Omar
Ingeniero de Software
Como todos los grandes ingenieros, Hairil es un ávido aprendiz. Está refinando su conocimiento de C#, Python y Java, usando ese conocimiento para agregar valor a los miembros del equipo en Iron Software. Hairil se unió al equipo de Iron Software desde la Universiti Teknologi MARA en Malasia, donde se ...
Leer más
¿Listo para empezar?
Nuget Descargas 1,935,276 | Versión: 2025.11 recién lanzado