使用 C# 快速輕鬆地讀取 Code 39 BARCODE
IronBarcode 透過在 C# 中使用 BarcodeReaderOptions 類別並指定 BarcodeEncoding.Co/de39,以及在需要時啟用 UseCode39ExtendedMode 以支援完整的 ASCII 字元,從而簡化標準與擴充版 Code 39 BARCODE 的讀取作業。
Code 39 是一種多功能 BARCODE 格式,廣泛應用於庫存管理、物流及工業領域。 Code 39 BARCODE 的長度可變,使其能靈活適用於各種使用情境。
原始的 Standard Code 39 編碼包含大寫字母(A-Z)、數字(0-9)以及若干特殊字元(空格、-、$、+、% 和 .)。 這對於基本的 ID 來說效果良好,但現代應用程式通常需要編碼所有 128 個 ASCII 字元。 Code 39 Extended 規格正是為此需求而設計。
本指南將示範如何使用 IronBarcode 讀取標準版與擴展版的 Code 39 條碼。 無論您是建置庫存管理系統、追蹤貨件,還是處理工業 BARCODE,IronBarcode 都能提供可靠的 Code 39 讀取功能。 如需完整了解BarCode讀取功能,請參閱我們的BarCode快速入門指南。
快速入門:使用 C# 讀取 Code 39 BARCODE
using IronBarcode 的 BarcodeReader,僅需一行程式碼即可從圖片中解碼 Code 39 條碼。 立即開始——指定編碼類型、上傳您的圖片,並查看結果。
-
using NuGet 套件管理員安裝 https://www.nuget.org/packages/BarCode
PM > Install-Package BarCode -
請複製並執行此程式碼片段。
IronBarCode.BarcodeReader.Read("code39.png", new IronBarCode.BarcodeReaderOptions { ExpectBarcodeTypes = IronBarCode.BarcodeEncoding.Co/de39 }).First().ToString(); -
部署至您的生產環境進行測試
立即透過免費試用,在您的專案中開始使用 IronBarcode
如何在 C# 中讀取 Code 39 BARCODE
- 下載 IronBarcode C# 程式庫以讀取 Code39 條碼
- 初始化一個新的
BarcodeReaderOptions - 請在選項中指定
BarcodeEncoding.Co/de39選項中 - 使用以下方式讀取 Code 39 BARCODE:
Read - 驗證結果並將其PRINT至控制台
如何讀取標準 Code 39 BarCode?
using IronBarcode 讀取 Code 39 BARCODE 非常簡單。 首先,初始化一個新的 BarcodeReaderOptions,並將BARCODE類型指定為 BarcodeEncoding.Co/de39。 這能透過精確告知掃描器應識別的BarCode格式,從而優化掃描效果。
接著,使用 Read 方法讀取 BARCODE,並將 BARCODE 圖像和選項作為參數傳入。 接著遍歷結果集合,並將每個BARCODE的字串值PRINT至控制台。 如需更進階的設定,請參閱我們關於BarCode讀取器設定的詳細指南。
標準 Code 39 BARCODE 長什麼樣子?
此圖像包含一個標準的 Code 39 BARCODE。 請注意,BARCODE如何同時以條紋形式及下方的人類可讀文字形式顯示其編碼值。 這種雙重表示形式是 Code 39 BARCODE 在工業與物流應用中的典型特徵。
我需要什麼程式碼才能讀取標準 Code 39 條碼?
:path=/static-assets/barcode/content-code-examples/how-to/read-code39-barcode.cs
using IronBarCode;
using System;
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Tell the reader to only look for Code 39.
ExpectBarcodeTypes = BarcodeEncoding.Code39
};
// Read barcode(s) from the image file using the specified options
var results = BarcodeReader.Read("code39.png", options);
// Loop through each BarcodeResult found in the image
foreach (var result in results)
{
// Print the decoded string value of the standard Code 39 barcode
Console.WriteLine(result.ToString());
}
Imports IronBarCode
Imports System
Dim options As New BarcodeReaderOptions() With {
.ExpectBarcodeTypes = BarcodeEncoding.Code39
}
' Read barcode(s) from the image file using the specified options
Dim results = BarcodeReader.Read("code39.png", options)
' Loop through each BarcodeResult found in the image
For Each result In results
' Print the decoded string value of the standard Code 39 barcode
Console.WriteLine(result.ToString())
Next
指定預期的BarCode類型可顯著提升讀取效能。 IronBarcode 無需耗時搜尋其他 BarCode 格式,這對於大量圖像集的批次處理尤為有益。 透過我們的讀取速度選項指南,進一步了解如何優化BarCode讀取效能。
我應該期待什麼樣的翻譯成果?
主控台輸出顯示已成功解碼自 Code 39 BARCODE 的值"ABC-1234"。 退出代碼 0 表示執行成功且無錯誤。 在實際應用中,針對BarCode可能無法被識別的情況,應實作適當的錯誤處理機制。 若遇到問題,請參閱我們的"無法識別BarCode"疑難排解指南。
如何讀取擴展型 Code 39 BARCODE?
讀取擴展版 Code 39 BARCODE 的流程與標準 Code 39 BARCODE 類似。主要差異在於需將 UseCode39ExtendedMode 屬性設定為 true。
此設定指示 IronBarcode 解析特殊字元組合(例如 +T、%O),並將其解碼為全 ASCII 等效字元(例如 t、!)。 Extended Code 39 使用兩字元序列來表示標準字元集以外的字元。 這會使BARCODE長度略微增加,但能支援小寫字母、更多標點符號及控制字元的編碼。
何時該使用 Extended Code 39?
當您的應用程式需要編碼以下內容時,Extended Code 39 是理想選擇:
- 混合大小寫文字(大寫與小寫字母)
- 特殊字元如 @、#、&、!、?
- 用於資料傳輸的控制字元
- 完整支援 ASCII 字元集
常見的應用場景包括醫療系統、文件追蹤,以及需要豐富資料編碼的高階庫存管理。
擴展型 Code 39 BARCODE 長什麼樣子?
此圖像包含一個擴展型 Code 39 BARCODE。 值 Test-Data! 包含小寫字母和感嘆號,這些字元僅存在於完整 ASCII 字元集,且需要啟用擴展模式。
使用 Extended Code 39 需要哪些代碼?
:path=/static-assets/barcode/content-code-examples/how-to/read-extended-code39-barcode.cs
using IronBarCode;
using System;
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
// Enable extended Code 39 mode
UseCode39ExtendedMode = true,
// Specify that we are expecting Code 39 barcodes
ExpectBarcodeTypes = BarcodeEncoding.Code39
};
// Read barcode(s) from the extended code 39 image
var results = BarcodeReader.Read("code39extended.png", options);
// Loop through each BarcodeResult found in the image
foreach (var result in results)
{
// Print the fully decoded ASCII string (e.g., "Test-Data!")
Console.WriteLine(result.ToString());
}
Imports IronBarCode
Imports System
Dim options As New BarcodeReaderOptions() With {
.UseCode39ExtendedMode = True,
.ExpectBarcodeTypes = BarcodeEncoding.Code39
}
' Read barcode(s) from the extended code 39 image
Dim results = BarcodeReader.Read("code39extended.png", options)
' Loop through each BarcodeResult found in the image
For Each result In results
' Print the fully decoded ASCII string (e.g., "Test-Data!")
Console.WriteLine(result.ToString())
Next
啟用擴展模式後,我應期待獲得什麼樣的輸出結果?
進階 Code 39 讀取技術
處理多個BarCode
IronBarcode 能自動偵測並讀取單一影像中的多個 Code 39 BarCode。 Read 方法會傳回一組結果,讓您能夠個別處理每個 BarCode。 若您的應用程式需處理整頁BarCode或複雜文件,請參閱我們關於讀取多個BarCode的指南。
處理畫質不佳的圖片
Code 39 BARCODE有時會出現在條件不佳的情況下——例如褪色的列印、傾斜的角度,或是低解析度的掃描。 IronBarcode 內建強大的影像校正濾鏡,可顯著提升讀取準確度:
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
ExpectBarcodeTypes = BarcodeEncoding.Co/de39,
UseCode39ExtendedMode = true,
// Apply image correction filters
ImageFilters = new ImageFilterCollection() {
new SharpenFilter(),
new ContrastFilter(),
new BrightnessFilter()
}
};
BarcodeReaderOptions options = new BarcodeReaderOptions()
{
ExpectBarcodeTypes = BarcodeEncoding.Co/de39,
UseCode39ExtendedMode = true,
// Apply image correction filters
ImageFilters = new ImageFilterCollection() {
new SharpenFilter(),
new ContrastFilter(),
new BrightnessFilter()
}
};
Imports System
Dim options As New BarcodeReaderOptions() With {
.ExpectBarcodeTypes = BarcodeEncoding.Co.de39,
.UseCode39ExtendedMode = True,
.ImageFilters = New ImageFilterCollection() From {
New SharpenFilter(),
New ContrastFilter(),
New BrightnessFilter()
}
}
效能優化
針對大量BarCode讀取應用,請考慮以下優化策略:
- 明確指定 BARCODE 類型 - 請務必設定
ExpectBarcodeTypes以避免不必要的掃描 - 採用適當的閱讀速度 - 根據您的需求平衡速度與準確性
- 並行處理影像 - 利用多執行緒進行批次處理
- 預處理圖片 - 僅在必要時進行修正以維持效能
摘要
IronBarcode 簡化了 C# 中的 Code 39 BarCode 讀取流程,無論處理標準格式或擴展格式皆適用。 關鍵步驟如下:
掌握這些基礎知識後,您便準備好將 Code 39 BARCODE 讀取功能整合至您的 .NET 應用程式中。 如需完整的 API 文件及更多 BarCode 格式,請參閱我們的全面 API 參考指南。 如需針對 Code 39 的實作範例,請參閱我們的 Code 39 專屬教學指南。
常見問題
什麼是Code 39,它的常見用途是什麼?
Code 39是一種多功能條碼格式,廣泛應用於庫存、物流和工業應用。它可以根據不同用途變化,標準Code 39編碼大寫字母(A-Z)、數字(0-9)及一些特殊字符,而Code 39 Extended則可編碼所有128個ASCII字符。IronBarcode提供了可靠的能力來讀取標準和擴展的Code 39變體。
如何在C#中讀取標準的Code 39條碼?
要使用IronBarcode讀取Code 39條碼,首先初始化一個新的BarcodeReaderOptions並指定條碼類型為BarcodeEncoding.Code39。然後使用Read方法,將條碼圖像和選項作為參數傳入。最後,迭代結果集合以訪問每個條碼的字串值。
標準Code 39可以編碼哪些字符?
標準Code 39編碼大寫字母(A-Z)、數字(0-9)及一些特殊字符,包括空格、連字符(-)、美元符號($)、加號(+)、百分號(%)和句號(.)。若要編碼所有128個ASCII字符,需要使用Code 39 Extended模式,IronBarcode支持通過UseCode39ExtendedMode選項。
標準和擴展Code 39有何不同?
標準Code 39僅限於大寫字母、數字和一些特殊字符,非常適合基本的ID。Code 39 Extended則滿足了現代應用程序需要編碼所有128個ASCII字符的需求。IronBarcode通過在BarcodeReaderOptions類中啟用UseCode39ExtendedMode,簡化了對這兩種變體的讀取,提供完整的ASCII字符支持。
Code 39條碼可以包含可讀文字嗎?
可以,Code 39條碼通常會在條碼下方同時顯示其編碼值的條碼和可讀文字。這種雙重表示在工業和物流應用中很常見,使操作員更容易驗證條碼內容。IronBarcode在無論是否存在可讀文字的情況下都能讀取條碼數據。
使用IronBarcode進行條碼操作有什麼好處?
IronBarcode提供了如易於整合、支持多種條碼格式、高品質圖像生成和強大讀取能力等好處,使其成為C#中條碼操作的全面工具。
IronBarcode是否提供自定義條碼外觀的支持?
是的,IronBarcode提供了廣泛的條碼外觀自定義選項,包括顏色、大小和文字註釋,讓您可以根據具體設計需求定制條碼。
IronBarcode如何幫助改善業務流程效率?
IronBarcode通過使條碼生成和讀取快速且準確來提高業務流程效率,減少手動數據輸入錯誤,並改善庫存和資產追蹤。
將IronBarcode實現於專案中需要什麼程式設計技能?
基本的C#程式設計知識足以將IronBarcode實現於專案中,因為它提供了簡單的方法和全面的文檔來指導開發者。
IronBarcode適合於小型專案和大型企業應用嗎?
IronBarcode設計為可擴展且多功能,使其適合小型專案和需要強大條碼解決方案的大型企業應用。

