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 の配列を返し、各結果のテキスト値をループして、バーコードの値(12345)を印刷します。






