IronBarcode 无法识别 MSI 条码
This article was translated from English: Does it need improvement?
Translated
View the article in English
问题
使用IronBarcode库创建MSI条码时,某些情况下BarcodeReader.Read方法无法读取生成的MSI条码,导致扫描结果为空以及预期的条码值。
解决方案
为确保BarcodeReaderOptions参数。 在ExpectedBarcodeTypes。 这样,Read方法可以识别由IronBarcode生成的MSI条码以及任何外部的MSI条码。
下面是一个如何将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
$vbLabelText
$csharpLabel
在示例中,我们首先实例化一个新的ExpectedBarcodeTypes赋值,指示IronBarcode预期为MSI条码。 之后,我们在for循环中打印出条码的值,即12345,因为BarcodeResults数组,并遍历每个结果获取文本值。
准备开始了吗?
Nuget 下载 2,331,688 | 版本: 2026.7 刚刚发布

