한 번에 여러 바코드를 읽는 방법
IronBarcode는 ExpectMultipleBarcodes = true을 설정하여 이미지 및 PDF에서 여러 BARCODE를 동시에 읽을 수 있게 함으로써, 물류, 소매 및 재고 관리 애플리케이션의 데이터 처리 과정을 간소화합니다. 창고 시스템, 소매 판매 시점 애플리케이션, 문서 처리 솔루션을 구축하든 관계없이 IronBarcode의 고급 판독 기능은 필요한 신뢰성과 성능을 제공합니다.
빠른 시작: 쉽게 이미지를 스캔하여 모든 바코드 읽기
이 예제는 IronBarcode를 사용하여 이미지에 포함된 모든 바코드를 얼마나 빨리 스캔할 수 있는지 보여줍니다. 원하는 BARCODE 유형 옆에 ExpectMultipleBarcodes = true을 설정하기만 하면 됩니다. 정형화된 문구도, 번거로움도 없습니다.
-
NuGet 패키지 관리자를 사용하여 https://www.nuget.org/packages/BarCode 설치하기
PM > Install-Package BarCode -
다음 코드 조각을 복사하여 실행하세요.
var results = IronBarCode.BarcodeReader.Read("image.png", new IronBarCode.BarcodeReaderOptions { ExpectMultipleBarcodes = true, ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.AllOneDimensional }); -
실제 운영 환경에서 테스트할 수 있도록 배포하세요.
무료 체험판으로 오늘 프로젝트에서 IronBarcode 사용 시작하기
최소 워크플로우(5단계)
- C# 라이브러리를 다운로드하여 여러 바코드를 읽으세요
Read메서드를 사용하여 다양한 이미지 형식에서 바코드 값을 추출하세요ExpectMultipleBarcodes속성을 사용하여 단일 또는 여러 바코드 읽기를 구성하세요ExpectMultipleBarcodes속성을 false로 설정하여 성능을 향상시키세요- 바코드 값을 출력하세요
이미지에서 여러 바코드를 어떻게 읽습니까?
기본적으로 IronBarcode는 문서를 계속 스캔하여 여러 바코드를 읽습니다. 그러나 여러 바코드가 있을 경우에도 하나의 바코드 값만 반환되는 경우가 있었습니다. 이를 해결하기 위해 여러 바코드를 읽을 수 있도록 설정을 사용자 지정하세요, 아래 예시를 참조하세요. ExpectMultipleBarcodes 속성은 BarcodeReaderOptions 및 PdfBarcodeReaderOptions 클래스 모두에 존재하므로, 이미지 및 PDF 문서에서 BarCode를 읽는 데 사용할 수 있습니다.
: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
ExpectMultipleBarcodes를 true로 설정하면 IronBarcode가 문서 전체를 스캔하여 여러 BarCode를 찾아 BarcodeResults 변수에 저장할 수 있습니다. foreach 루프를 사용하면 모든 BarCode 값에 쉽게 접근하여 콘솔에 PRINT할 수 있습니다.
고급 다중 바코드 판독 시나리오
다중 바코드를 다루는 경우 추가 구성이 필요한 시나리오를 마주할 수 있습니다. 여기 복잡한 문서에서 다양한 형식의 다중 바코드를 읽는 방법을 보여주는 포괄적인 예시가 있습니다:
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("---");
}
Imports IronBarCode
Imports System
Imports System.Linq
' Configure advanced options for mixed barcode types
Dim advancedOptions As New BarcodeReaderOptions() With {
.ExpectMultipleBarcodes = True,
' Read both 1D and 2D barcodes
.ExpectBarcodeTypes = BarcodeEncoding.AllOneDimensional Or BarcodeEncoding.QRCode Or BarcodeEncoding.DataMatrix,
' Apply image correction filters for better accuracy
.ImageFilters = New ImageFilterCollection() From {
New SharpenFilter(),
New ContrastFilter()
},
' Set speed vs accuracy balance
.Speed = ReadingSpeed.Balanced
}
' Read from various sources
Dim imageResults = BarcodeReader.Read("mixed-barcodes.jpg", advancedOptions)
Dim pdfResults = BarcodeReader.ReadPdf("document-with-barcodes.pdf", advancedOptions)
' Process results with error handling
For Each 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("---")
Next
이 고급 예제는 몇 가지 중요한 기능을 보여줍니다:
- 혼합된 바코드 형식 지원: 다양한 바코드 인코딩 유형 결합
- 이미지 교정 필터: 읽기 정확도를 향상시키기 위해 이미지 필터 사용
- 읽기 속도 최적화: 읽기 속도 옵션으로 속도와 정확도 균형 유지
- 신뢰도 점수: 각 감지된 바코드에 대한 신뢰도 임계값 접근
향상된 성능을 위해 단일 바코드를 어떻게 읽을 수 있습니까?
IronBarcode는 이미지는 물론 PDF에서 단일 및 다중 바코드를 읽습니다. 기본적으로 엔진은 바코드가 하나만 있어도 전체 문서를 스캔합니다. 단일 BARCODE를 읽을 때 성능을 높이려면 ExpectMultipleBarcodes을 false로 설정하십시오. 이렇게 하면 첫 번째 바코드를 탐지한 후 전체 문서를 스캔하지 않으므로 더 빠르게 바코드를 검색할 수 있습니다. 아래 코드는 이 접근법을 보여줍니다.
: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
이 예제에서는 이전과 마찬가지로 여러 BARCODE가 포함된 동일한 이미지를 사용했으나, ExpectMultipleBarcodes를 false로 설정했습니다. 그 결과 첫 번째 바코드 값만 반환되며 첫 번째 바코드가 검색되면 스캔 프로세스가 중지됩니다.
크롭 영역을 사용하여 단일 바코드 읽기 최적화
단일 BARCODE를 읽을 때 더 나은 성능을 얻으려면 ExpectMultipleBarcodes = false 설정을 자르기 영역 지정과 함께 사용하십시오. 이 기술은 바코드의 대략적인 위치를 알고 있을 때 특히 유용합니다:
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");
}
Imports IronBarCode
Imports IronSoftware.Drawing
' Define a crop region where the barcode is likely located
Dim cropRegion As New Rectangle(100, 100, 300, 200)
' Configure options for optimal single barcode reading
Dim optimizedOptions As New BarcodeReaderOptions() With {
.ExpectMultipleBarcodes = False,
.ExpectBarcodeTypes = BarcodeEncoding.Code128,
.CropArea = cropRegion,
.Speed = ReadingSpeed.Faster
}
' Read with optimized settings
Dim result = BarcodeReader.Read("product-label.png", optimizedOptions).FirstOrDefault()
If result IsNot Nothing Then
Console.WriteLine($"Barcode found: {result.Value}")
Console.WriteLine($"Read time: {result.ReadTime}ms")
End If
단일 바코드 읽기가 얼마나 더 빠른가요?
ExpectMultipleBarcodes = false을 설정하면 단일 BarCode 판독 효율이 크게 향상됩니다. 성능 향상은 고해상도 이미지 작업이나 고처리량 애플리케이션에서 비동기 바코드 읽기를 구현할 때 특히 눈에 띕니다.
제공된 코드 스니펫을 바탕으로, 동일한 시스템에서 ExpectMultipleBarcodes = true을 설정했을 때와 false를 설정했을 때의 성능 차이에 대한 대략적인 추정치는 다음과 같습니다:
| ExpectMultipleBarcodes = true | ExpectMultipleBarcodes = false |
|---|---|
| 00.91 초 | 00.10 초 |
이는 단일 바코드를 읽을 때 약 9배 성능 향상을 나타냅니다. 실제 성능 향상은 다음에 따라 달라집니다:
- 이미지 해상도 및 복잡성
- 이미지에 존재하는 바코드의 수
- 선택된 바코드 형식
- 적용된 이미지 필터
- 하드웨어 사양
다중 바코드 읽기에 대한 모범 사례
다중 바코드 읽기를 생산 애플리케이션에 구현할 때 다음 모범 사례를 고려하십시오:
-
예상 BarCode 유형 명시:
BarcodeEncoding.All를 사용하는 대신, 예상되는 형식만 명시하십시오. 이렇게 하면 성능이 크게 향상됩니다. -
적절한 이미지 형식 사용: 최상의 결과를 얻으려면 고대비 이미지를 사용하십시오. 최적의 바코드 이미지 생성에 대해 자세히 알아보기.
-
불완전한 바코드 처리: 실제 세계의 바코드는 손상되거나 인쇄가 불량할 수 있습니다. 이미지 보정 기술을 사용하여 읽기 성공률을 높이십시오.
-
스트림 처리: 대량 배치의 경우 메모리 사용을 최적화하기 위해 스트림에서 읽기를 고려하십시오.
- 오류 처리: 항상 바코드를 읽을 수 없는 시나리오에 대한 적절한 오류 처리를 구현하십시오:
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
}
Imports System
Try
Dim results = BarcodeReader.Read("barcodes.png", New BarcodeReaderOptions With {
.ExpectMultipleBarcodes = True
})
If Not results.Any() Then
Console.WriteLine("No barcodes found in the image")
Else
Console.WriteLine($"Found {results.Count()} barcodes")
End If
Catch ex As Exception
Console.WriteLine($"Error reading barcodes: {ex.Message}")
' Log error for debugging
End Try
이러한 관행을 따르고 IronBarcode의 포괄적인 기능을 활용하면 다양한 산업 및 사용 사례에서 다중 바코드 읽기 시나리오를 효율적으로 처리하는 강력한 애플리케이션을 구축할 수 있습니다.
자주 묻는 질문
C#에서 하나의 이미지에 있는 여러 개의 바코드를 어떻게 읽을 수 있나요?
IronBarcode를 사용하면 BarcodeReaderOptions에서 ExpectMultipleBarcodes = true로 설정하여 단일 이미지에서 여러 개의 바코드를 읽을 수 있습니다. 이렇게 하면 IronBarcode가 전체 문서를 스캔하고 발견된 모든 바코드를 BarcodeResults 컬렉션에 담아 반환하며, 이 컬렉션을 순회하면서 바코드를 읽을 수 있습니다.
이미지에 있는 모든 바코드를 가장 빠르게 스캔하는 방법은 무엇인가요?
가장 빠른 방법은 IronBarcode의 Read 메서드를 ExpectMultipleBarcodes = true 옵션과 함께 사용하는 것입니다. 예를 들어, 다음과 같이 작성할 수 있습니다. var results = IronBarCode.BarcodeReader.Read("image.png", new IronBarCode.BarcodeReaderOptions { ExpectMultipleBarcodes = true }). 이 간단한 코드는 복잡한 설정 없이 모든 바코드 값을 추출합니다.
PDF 문서와 이미지에서 여러 개의 바코드를 읽을 수 있나요?
예, IronBarcode는 이미지와 PDF 문서 모두에서 여러 개의 바코드를 읽는 기능을 지원합니다. ExpectMultipleBarcodes 속성은 BarcodeReaderOptions 및 PdfBarcodeReaderOptions 클래스 모두에서 사용할 수 있으며, 이를 통해 모든 문서 유형에 대해 여러 바코드 읽기 기능을 구성할 수 있습니다.
ExpectMultipleBarcodes를 true로 설정하지 않으면 어떻게 되나요?
기본적으로 IronBarcode는 문서에서 여러 바코드를 지속적으로 스캔합니다. 그러나 경우에 따라 여러 바코드가 존재하더라도 하나의 바코드 값만 반환될 수 있습니다. ExpectMultipleBarcodes = true로 설정하면 IronBarcode가 문서의 모든 바코드를 스캔하고 반환하도록 명시적으로 지정할 수 있습니다.
여러 개의 바코드를 읽은 후 개별 바코드 값을 어떻게 확인할 수 있나요?
IronBarcode를 사용하여 여러 바코드를 읽은 후, 결과는 BarcodeResults 변수에 저장됩니다. foreach 루프를 사용하여 컬렉션을 순회하고 각 바코드의 값, 텍스트 및 형식 속성을 처리함으로써 개별 바코드 값에 쉽게 접근할 수 있습니다.
여러 개의 바코드를 읽는 기술은 소매 및 물류 분야에 적합할까요?
네, IronBarcode의 다중 바코드 인식 기능은 소매점 POS 시스템, 창고 관리, 물류 추적 및 재고 관리 애플리케이션에 이상적입니다. 배송 라벨, 제품 카탈로그 또는 재고 목록에 있는 모든 바코드를 동시에 효율적으로 스캔하여 데이터 처리를 간소화합니다.
여러 바코드를 읽을 때 특정 바코드 유형을 지정할 수 있나요?
네, IronBarcode에서는 ExpectBarcodeTypes 속성을 사용하여 예상되는 바코드 유형을 지정할 수 있습니다. AllOneDimensional, QRCode와 같은 특정 형식 또는 지원되는 바코드 유형의 조합을 스캔하도록 설정하여 스캔 성능을 최적화할 수 있습니다.
ExpectMultipleBarcodes 설정이 스캔 성능에 영향을 미치나요?
ExpectMultipleBarcodes = false로 설정하면 문서에 바코드가 하나만 있는 경우 성능이 향상될 수 있습니다. IronBarcode는 첫 번째 바코드를 찾으면 스캔을 중지하므로 단일 바코드 시나리오에서 더 빠른 속도를 제공하는 동시에 필요에 따라 여러 바코드를 읽을 수 있는 유연성도 제공합니다.
IronBarcode를 프로젝트에 구현하려면 어떤 프로그래밍 기술이 필요하나요?
C# 프로그래밍의 기본 지식만 있으면 IronBarcode를 프로젝트에 구현하기에 충분합니다. IronBarcode는 개발자를 안내할 수 있는 간단한 메서드와 포괄적인 문서를 제공합니다.
IronBarcode는 소규모 프로젝트와 대규모 Enterprise 응용 프로그램 모두에 적합합니까?
IronBarcode는 확장 가능하고 다재다능하게 설계되어 소규모 프로젝트뿐만 아니라 견고한 바코드 솔루션이 필요한 대규모 Enterprise 응용 프로그램에 적합합니다.

