複数のバーコードを一度に読み取る方法

Hairil related to 複数のバーコードを一度に読み取る方法
ハイリル ハシミ ビン オマル
2023年7月25日
更新済み 2025年1月8日
共有:
This article was translated from English: Does it need improvement?
Translated
View the article in English

複数のバーコードを同時に読み取ることは、効率的なデータ処理を可能にするため、物流、小売、医療、在庫管理などのさまざまな業界にとって重要です。 IronBarcodeを使用すると、この機能を簡単に実現でき、運用の合理化と生産性の向上に強力なツールとなります。

IronBarcodeを始める

今日から無料トライアルでIronBarcodeをあなたのプロジェクトで使い始めましょう。

最初のステップ:
green arrow pointer



複数のバーコードを読み取る例

デフォルトでは、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
$vbLabelText   $csharpLabel

コードスニペットで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
$vbLabelText   $csharpLabel

上記のコードスニペットでは、以前と同様に複数のバーコードを含む同じ画像を使用しましたが、今回はExpectMultipleBarcodesをfalseに設定しました。 その結果、最初のバーコード値のみが返され、最初のバーコードが取得されるとスキャンプロセスは停止します。

パフォーマンス比較

ExpectMultipleBarcodesをfalseに設定すると、画像内の単一バーコードの読み取り効率が大幅に向上します。

提供されたコードスニペットを使用して、同じマシンでExpectMultipleBarcodeをtrueとfalseに設定した場合のパフォーマンスの違いのおおよその見積もりはこちらです:

ExpectMultipleBarcodes = true
Hairil related to パフォーマンス比較
ハイリル ハシミ ビン オマル
ソフトウェアエンジニア
すべての優れたエンジニアと同じように、Hairilは熱心な学習者です。C#、Python、およびJavaの知識を洗練させ、その知識を活かしてIron Softwareのチームメンバーに価値を提供しています。Hairilはマレーシアのマラ工科大学(Universiti Teknologi MARA)で化学およびプロセス工学の学士号を取得し、Iron Softwareチームに加わりました。