複数のバーコードを一度に読み取る方法
複数のバーコードを同時に読み取ることは、効率的なデータ処理を可能にするため、物流、小売、医療、在庫管理などのさまざまな業界にとって重要です。 IronBarcodeを使用すると、この機能を簡単に実現でき、運用の合理化と生産性の向上に強力なツールとなります。
IronBarcodeを始める
今日から無料トライアルでIronBarcodeをあなたのプロジェクトで使い始めましょう。
複数のバーコードを一度に読み取る方法
複数のバーコードを読み取る例
デフォルトでは、IronBarcodeは複数のバーコードを読み取るために文書を継続的にスキャンします。 しかし、画像内に複数のバーコードが存在する場合でも、1つのバーコード値しか返されないことがあります。 この問題に対処するために、ユーザーは以下のコードスニペットのように、複数のバーコードの読み取りを有効にするよう設定をカスタマイズできます。 ExpectMultipleBarcode プロパティは、BarcodeReaderOptions クラスとPdfBarcodeReaderOptions クラスの両方に存在し、ユーザーが画像およびPDFドキュメントのバーコードを読み取るために使用することができます。
サンプル画像

: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は複数のバーコードをドキュメント全体からスキャンし、それらをBarcodeResults変数に格納します。 foreachループを使用すると、ユーザーはすべてのバーコード値に簡単にアクセスしてコンソールに印刷できます。
単一のバーコードを読み取る例
IronBarcodeは、画像やPDF内の単一および複数のバーコードを読み取ることができます。 デフォルトでは、エンジンはバーコードが1つしかない場合でもドキュメント全体をスキャンします。 ただし、1つのバーコードを読み取る際のパフォーマンスを向上させるために、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
上記のコードスニペットでは、以前と同様に複数のバーコードを含む同じ画像を使用しましたが、今回はExpectMultipleBarcodesをfalseに設定しました。 その結果、最初のバーコード値のみが返され、最初のバーコードが取得されるとスキャンプロセスは停止します。
パフォーマンス比較
ExpectMultipleBarcodesをfalseに設定すると、画像内の単一バーコードの読み取り効率が大幅に向上します。
提供されたコードスニペットを使用して、同じマシンでExpectMultipleBarcodeをtrueとfalseに設定した場合のパフォーマンスの違いのおおよその見積もりはこちらです: