IronBarCode は MSI バーコードを認識できませんでした
問題
IronBarcodeライブラリを使用して MSI バーコードを作成する場合、BarcodeReader.Read メソッドでは生成された MSI バーコードを読み取ることができず、スキャンが空になり、バーコードから期待される値が返される場合があります。
解決策
BarcodeReader.Read が MSI バーコードを読み取れるようにするには、Read メソッドにオプションの 2 番目の BarcodeReaderOptions パラメータを指定する必要があります。 BarcodeReaderOptions 内では、値 ExpectedBarcodeTypes を割り当てることで、読み取ろうとしているバーコードの種類を明示的に指定します。 この方法では、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"
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 As New BarcodeReaderOptions With {.ExpectBarcodeTypes = BarcodeEncoding.MSI}
' Read barcode with additional barcodeReaderOptions from above
Dim barcodeResults = BarcodeReader.Read("msi.png", barcodeReaderOptions)
' Using a for loop and print out the result
For Each result As BarcodeResult In barcodeResults
Console.WriteLine(result.Text)
' Output: 12345
Next result
この例では、最初に新しい BarcodeReaderOptions 変数をインスタンス化し、次に ExpectedBarcodeTypes に BarcodeEncoding.MSI 列挙型を割り当てて、 IronBarcodeに代わりに MSI バーコードを期待するように指示します。 その後、barcodeResults が BarcodeResults の配列を返すため、for ループでバーコードの値 (12345) を出力し、各結果をループしてテキスト値を求めます。

