IronBarCode は MSI バーコードを認識できませんでした

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

問題

IronBarcodeライブラリを使用して MSI バーコードを作成する場合、BarcodeReader.Read メソッドでは生成された MSI バーコードを読み取ることができず、スキャンが空になり、バーコードから期待される値が返される場合があります。

解決策

BarcodeReader.Read が MSI バーコードを読み取れるようにするには、Read メソッドにオプションの 2 番目の BarcodeReaderOptions パラメータを指定する必要があります。 BarcodeReaderOptions 内では、値 ExpectedBarcodeTypes を割り当てることで、読み取ろうとしているバーコードの種類を明示的に指定します。 この方法では、Read メソッドは、 IronBarcodeから生成された MSI バーコードだけでなく、外部の MSI バーコードも認識します。

以下は、BarcodeReaderOptionsBarcodeReader.Read に適用する方法の簡単な例です。

コード例

// Creating MSI Barcode with the value "12345"
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI);

// Save barcode as image
myBarcode.SaveAsImage("msi.png");

// Reading MSI
var barcodeReaderOptions = new BarcodeReaderOptions
{
     // Assigning BarcodeEncoding.MSI to ExpectBarcodeType to ensure that IronBarcode expects MSI type barcodes specifically 
  ExpectBarcodeTypes = BarcodeEncoding.MSI,
};

// Read barcode with additional barcodeReaderOptions from above
var barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions);

// Using a for loop and print out the result 
foreach (BarcodeResult result in barcodeResults)
{
  Console.WriteLine(result.Text);
    // Output: 12345 
}
// Creating MSI Barcode with the value "12345"
var myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI);

// Save barcode as image
myBarcode.SaveAsImage("msi.png");

// Reading MSI
var barcodeReaderOptions = new BarcodeReaderOptions
{
     // Assigning BarcodeEncoding.MSI to ExpectBarcodeType to ensure that IronBarcode expects MSI type barcodes specifically 
  ExpectBarcodeTypes = BarcodeEncoding.MSI,
};

// Read barcode with additional barcodeReaderOptions from above
var barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions);

// Using a for loop and print out the result 
foreach (BarcodeResult result in barcodeResults)
{
  Console.WriteLine(result.Text);
    // Output: 12345 
}
$vbLabelText   $csharpLabel

この例では、最初に新しい BarcodeReaderOptions 変数をインスタンス化し、次に ExpectedBarcodeTypesBarcodeEncoding.MSI 列挙型を割り当てて、 IronBarcodeに代わりに MSI バーコードを期待するように指示します。 その後、barcodeResultsBarcodeResults の配列を返すため、for ループでバーコードの値 (12345) を出力し、各結果をループしてテキスト値を求めます。

カーティス・チャウ
テクニカルライター

Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。

開発以外にも、CurtisはIoT(Internet of Things)への強い関心を持ち、ハードウェアとソフトウェアの統合方法を模索しています。余暇には、ゲームをしたりDiscordボットを作成したりして、技術に対する愛情と創造性を組み合わせています。

準備はできましたか?
Nuget ダウンロード 2,121,847 | バージョン: 2026.3 リリース
Still Scrolling Icon

まだスクロールしていますか?

すぐに証拠が欲しいですか? PM > Install-Package BarCode
サンプルを実行する 文字列が BarCode になるのを見る。