IronBarcode MSI バーコードが認識できませんでした
問題
IronBarcodeライブラリを使用してMSIバーコードを作成する際に、BarcodeReader.Readメソッドが生成されたMSIバーコードを読み取れない場合があり、空のスキャンとバーコードから期待される値が発生します。
解決策
MSIバーコードを読み取れるようにするために、BarcodeReader.Readには、Readメソッドのために二次的かつオプションのBarcodeReaderOptionsパラメーターを提供する必要があります。 BarcodeReaderOptionsの中で、読み取ろうとしているバーコードの種類をExpectBarcodeTypes値を割り当てることによって明示的に指定します。 このようにして、ReadメソッドはIronBarcodeから生成されたMSIバーコードだけでなく、外部のMSIバーコードも認識します。
以下にBarcodeReaderOptionsをBarcodeReader.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"
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI)
' Save barcode as image
myBarcode.SaveAsImage("msi.png")
' Reading MSI
Dim barcodeReaderOptions = New BarcodeReaderOptions With {
' Assigning BarcodeEncoding.MSI to ExpectBarcodeType to ensure that IronBarcode expects MSI type barcodes specifically
.ExpectBarcodeTypes = BarcodeEncoding.MSI
}
' Read barcode with additional barcodeReaderOptions from above
Dim barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions)
' Using a For Each loop and print out the result
For Each result As BarcodeResult In barcodeResults
Console.WriteLine(result.Text)
' Output: 12345
Next' Creating MSI Barcode with the value "12345"
Dim myBarcode = BarcodeWriter.CreateBarcode("12345", BarcodeWriterEncoding.MSI)
' Save barcode as image
myBarcode.SaveAsImage("msi.png")
' Reading MSI
Dim barcodeReaderOptions = New BarcodeReaderOptions With {
' Assigning BarcodeEncoding.MSI to ExpectBarcodeType to ensure that IronBarcode expects MSI type barcodes specifically
.ExpectBarcodeTypes = BarcodeEncoding.MSI
}
' Read barcode with additional barcodeReaderOptions from above
Dim barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions)
' Using a For Each loop and print out the result
For Each result As BarcodeResult In barcodeResults
Console.WriteLine(result.Text)
' Output: 12345
Next例では、最初に新しいBarcodeReaderOptions変数をインスタンス化し、次にExpectBarcodeTypesをBarcodeEncoding.MSI列挙型で割り当てて、IronBarcodeに代わりにMSIバーコードを期待するよう指示します。 その後、barcodeResultsがBarcodeResultsの配列を返すので、for ループでループして各結果のテキスト値を取り出し、バーコードの値(12345)を印刷します。
Curtis Chauは、カールトン大学でコンピュータサイエンスの学士号を取得し、Node.js、TypeScript、JavaScript、およびReactに精通したフロントエンド開発を専門としています。直感的で美しいユーザーインターフェースを作成することに情熱を持ち、Curtisは現代のフレームワークを用いた開発や、構造の良い視覚的に魅力的なマニュアルの作成を楽しんでいます。