IRONSOFTWAREHOME

IronBarcode 無法識別 MSI 條碼

Curtis Chau
Curtis Chau
Updated: 2025年8月20日

問題

當使用 IronBarcode 程式庫建立 MSI 條碼時,有時 BarcodeReader.Read 方法無法讀取生成的 MSI 條碼,結果導致掃描為空且條碼中預期的值。

解決方案

為確保 BarcodeReader.Read 能夠讀取 MSI 條碼,我們必須為 Read 方法提供第二個可選的 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 
}

在範例中,我們首先實例化一個新的 BarcodeReaderOptions 變數,然後將 ExpectedBarcodeTypes 賦值為 BarcodeEncoding.MSI 列舉,指示 IronBarcode 預期 MSI 條碼。 然後,我們在 for 迴圈中列印出條碼的值,這值為 12345,因為 barcodeResults 返回 BarcodeResults 的陣列並逐一遍歷每個結果以取得文字值。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

...
閱讀更多

準備好開始了嗎?

Nuget Downloads 2,422,100版本:2026.9剛剛發布

立即獲取您的免費30天試用金鑰
不需要信用卡或帳戶建立
C# NuGet程式庫,用於PDF
通過NuGet安裝

版本: 2026.9

PM > Install-Package BarCode
nuget.org/packages/BarCode/
  1. 在解決方案資源管理器中,右鍵點擊References,管理NuGet包
  2. 選擇瀏覽並搜尋"IronBarCode"
  3. 選擇包並安裝
C# PDF DLL
下載DLL

版本: 2026.9

  1. 下載並解壓IronBarCode至您的Solution目錄中的~/Libs等位置
  2. 在Visual Studio解決方案資源管理器中右鍵點擊References,選擇瀏覽,"IronBarCode.dll"

$999起的授權費用

Key in blue circle

立即免費取得 30 天試用金鑰

Your trial license will be sent to your email address

無任何限制。100% 解鎖。無需信用卡。

bullet_checked無需信用卡或建立帳號無任何限制。100% 解鎖。無需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
預訂您的免費即時演示
Booking Badge

全球數百萬工程師信賴

Iron Software的客戶標誌
獲取您的無義務諮詢
完成下方表單或發送電子郵件至sales@ironsoftware.com
您的詳細資訊將始終保密。
全球數百萬工程師信賴
Iron Software的客戶標誌
立即獲取您的30天試用金鑰
無需信用卡或帳戶建立