IronBarcode 无法识别 MSI 条码
Curtis Chau
Updated: 2025年8月20日
问题
使用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"
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在示例中,我们首先实例化一个新的ExpectedBarcodeTypes赋值,指示IronBarcode预期为MSI条码。 之后,我们在for循环中打印出条码的值,即12345,因为BarcodeResults数组,并遍历每个结果获取文本值。

技术作家
Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。
...
阅读更多