如何在C#中自定義和設計條碼
從OnBarcode遷移至IronBarcode
本指南涵蓋完整的從OnBarcode到IronBarcode的遷移路徑。 它討論了三步驟設置更改,為每個常見模式提供前後程式碼範例,將OnBarcode的API映射到其IronBarcode對應項,記錄遷移過程中出現的問題,並提供一份在考慮遷移完成前審核您的程式碼庫的搜索詞檢查清單。
為何從OnBarcode遷移
兩個SKU的採購開銷: OnBarcode對Generator SDK(僅線性和線性+2D層級)發布了永久定價,並將Reader SDK列為一個單獨定價的產品。 需要這兩種功能的組織必須針對兩個SKU完成兩次採購過程——選擇每種使用中的條碼型別的正確生成層級,然後單獨購買Reader——在確定總成本之前。 這種摩擦來自於兩次採購的重複而不是一個單項。
拆分產品開銷: 生成和讀取是單獨的產品,具有單獨的NuGet包,單獨的授權命名空間,單獨的授權鍵,和單獨的版本計畫。 使用兩個產品的項目必須在啟動時配置兩個授權鍵,跨升級跟蹤兩個包版本,並保持對兩個獨立發布周期的認識。 當一個最初只生成的項目新增了讀取需求時,必須為第二個產品重複整個採購和整合過程。
PDF工作流程空白: OnBarcode沒有對從PDF文件中讀取條碼的本地支援。 處理嵌入發票、運送清單、購買訂單或存檔掃描中的條碼的項目必須獲得一個單獨的PDF到圖像呈現庫,將其整合到流程中,分別管理其授權,並逐一將呈現的頁面傳遞給OnBarcode Reader SDK。這產生了一個雙依賴解決方案,而一個依賴解決方案本來就足夠。
API冗長度: OnBarcode生成器需要實例化一個BarHeight——然後調用生成方法。 使用一個靜態工廠API可以用顯著更少的程式碼生產相同的輸出。 大批量生成中,屬性分配模式會產生大量重複程式碼,必須審查和維護。
基本問題
雙授權配置是任何需要同時生成和讀取項目的最直接的摩擦點。 OnBarcode需要在啟動時對兩個不同的授權命名空間進行兩次單獨調用:
// OnBarcode: two products, two DLL references, no runtime key
// OnBarcode uses pre-licensed DLLs — the purchased DLL is already activated.
// There is no runtime SetLicense() call; the license is baked into the downloaded assembly.
using OnBarcode.Barcode;
using OnBarcode.Barcode;
// OnBarcode: two products, two DLL references, no runtime key
// OnBarcode uses pre-licensed DLLs — the purchased DLL is already activated.
// There is no runtime SetLicense() call; the license is baked into the downloaded assembly.
using OnBarcode.Barcode;
using OnBarcode.Barcode;
Imports OnBarcode.Barcode
Imports OnBarcode.Barcode
IronBarcode將其簡化為一個涵蓋所有功能的單一屬性分配——生成、讀取、PDF支援和批量操作——在一個鍵下:
// IronBarcode: one package, one key, one line
using IronBarCode;
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
// IronBarcode: one package, one key, one line
using IronBarCode;
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
Imports IronBarCode
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
應用中的每個條碼操作——無論是生成、讀取還是處理PDF——都在該單一配置下運行。
IronBarcode對比OnBarcode: 功能比較
| 功能 | OnBarcode | IronBarcode |
|---|---|---|
| 條碼生成 | 是 | 是 |
| 條碼讀取 | 分開的產品,分開的購買 | 包含 |
| PDF 條碼讀取 | 本地不支持 | 原生——不需要外部庫 |
| 讀取格式自動檢測 | 否——需要明確的BarcodeType[] |
是 |
| 結果元資料(格式、位置、頁面) | 不可用——僅原始string[] |
是——BarcodeResults附帶完整元資料 |
| 覆蓋Logo的QR碼 | 需要手動GDI+程式碼 | 內建 |
| 已發布價格 | 是——每個產品頁面(生成器層級+單獨的讀取器) | 是——單一頁面涵蓋所有功能 |
| 單一授權鍵涵蓋所有功能 | 否——每個產品單獨鍵 | 是 |
| NuGet發佈 | 可用,並與傳統DLL下載選項一起提供 | 自推出以來可用 |
| 源碼存取 | 僅限Unlimited Tier | 不提供 |
| 支持.NET 8 / 9 | 是 | 是 |
| Docker / 雲授權配置 | 手動 | 支援環境變數 |
快速入門:從OnBarcode到IronBarcode遷移
步驟1:移除OnBarcode包引用
如果您的項目使用NuGet包,請移除這兩個:
dotnet remove package OnBarcode.Barcode.Generator
dotnet remove package OnBarcode.Barcode.Reader
dotnet remove package OnBarcode.Barcode.Generator
dotnet remove package OnBarcode.Barcode.Reader
如果您的項目使用較舊的基於DLL的發佈,也請從您的.csproj中移除手動引用塊:
<ItemGroup>
<Reference Include="OnBarcode.Barcode">
<HintPath>lib\OnBarcode.Barcode.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Reference Include="OnBarcode.Barcode">
<HintPath>lib\OnBarcode.Barcode.dll</HintPath>
<Private>true</Private>
</Reference>
</ItemGroup>
從lib/目錄或其存放處刪除DLL文件。 將舊程式集留在新NuGet包旁邊會在編譯時產生命名空間衝突。
步驟2:新增IronBarcode
一個包涵蓋生成、讀取和PDF支援:
dotnet add package IronBarcode
dotnet add package IronBarcode
不需要第二個包來讀取。 不需要第二個包來支持PDF。
步驟3:更新命名空間並替換雙授權配置
用單一的IronBarcode導入替換兩個OnBarcode的using指令:
// Remove
using OnBarcode.Barcode;
using OnBarcode.Barcode;
// Add
using IronBarCode;
// Remove
using OnBarcode.Barcode;
using OnBarcode.Barcode;
// Add
using IronBarCode;
Imports IronBarCode
將雙重DLL引用替換為單一鍵分配。 在應用啟動早期,在任何條碼操作運行之前,放置此配置一次:
// Remove the OnBarcode DLL references and using directives
// Add
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
// Remove the OnBarcode DLL references and using directives
// Add
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY";
' Remove the OnBarcode DLL references and Imports statements
' Add
IronBarCode.License.LicenseKey = "YOUR-LICENSE-KEY"
程式碼遷移範例
程式碼128條碼生成
基本的程式碼128案例說明了屬性分配模式與靜態工廠模式。
OnBarcode方法:
using OnBarcode.Barcode;
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE128;
barcode.Data = "SHIP-2024-001";
barcode.Resolution = 96;
barcode.X = 1;
barcode.BarcodeHeight = 80;
barcode.ShowText = true;
barcode.drawBarcode("shipping-label.png");
using OnBarcode.Barcode;
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE128;
barcode.Data = "SHIP-2024-001";
barcode.Resolution = 96;
barcode.X = 1;
barcode.BarcodeHeight = 80;
barcode.ShowText = true;
barcode.drawBarcode("shipping-label.png");
Imports OnBarcode.Barcode
Dim barcode As New Linear()
barcode.Type = BarcodeType.CODE128
barcode.Data = "SHIP-2024-001"
barcode.Resolution = 96
barcode.X = 1
barcode.BarcodeHeight = 80
barcode.ShowText = True
barcode.drawBarcode("shipping-label.png")
IronBarcode 方法:
using IronBarCode;
BarcodeWriter.CreateBarcode("SHIP-2024-001", BarcodeEncoding.Code128)
.SaveAsPng("shipping-label.png");
using IronBarCode;
BarcodeWriter.CreateBarcode("SHIP-2024-001", BarcodeEncoding.Code128)
.SaveAsPng("shipping-label.png");
Imports IronBarCode
BarcodeWriter.CreateBarcode("SHIP-2024-001", BarcodeEncoding.Code128) _
.SaveAsPng("shipping-label.png")
資料和編碼型別以參數形式傳遞給CreateBarcode。 屬性如解析度和條碼高度並不需要來生產可掃描的輸出; 預設設置適用於大多數用途。 當需要自定義尺寸時,可以在SaveAsPng之間作為鏈式調用新增而不引入可變物件狀態。
帶有Logo的QR碼生成
帶Logo的QR碼需要OnBarcode回退到System.Drawing進行圖像覆蓋步驟。 IronBarcode將其作為內建操作提供。
OnBarcode方法:
using OnBarcode.Barcode;
using System.Drawing;
QRCode qr = new QRCode();
qr.Data = "https://example.com/product/4891";
qr.QRCodeDataMode = QRCodeDataMode.Auto;
qr.QRCodeECL = QRCodeECL.H; // H-level error correction required for logo overlay
Image qrImage = qr.drawBarcode();
using (Graphics g = Graphics.FromImage(qrImage))
{
Image logo = Image.FromFile("brand-logo.png");
int logoSize = qrImage.Width / 5;
int x = (qrImage.Width - logoSize) / 2;
int y = (qrImage.Height - logoSize) / 2;
g.DrawImage(logo, x, y, logoSize, logoSize);
}
qrImage.Save("product-qr.png");
using OnBarcode.Barcode;
using System.Drawing;
QRCode qr = new QRCode();
qr.Data = "https://example.com/product/4891";
qr.QRCodeDataMode = QRCodeDataMode.Auto;
qr.QRCodeECL = QRCodeECL.H; // H-level error correction required for logo overlay
Image qrImage = qr.drawBarcode();
using (Graphics g = Graphics.FromImage(qrImage))
{
Image logo = Image.FromFile("brand-logo.png");
int logoSize = qrImage.Width / 5;
int x = (qrImage.Width - logoSize) / 2;
int y = (qrImage.Height - logoSize) / 2;
g.DrawImage(logo, x, y, logoSize, logoSize);
}
qrImage.Save("product-qr.png");
Imports OnBarcode.Barcode
Imports System.Drawing
Dim qr As New QRCode()
qr.Data = "https://example.com/product/4891"
qr.QRCodeDataMode = QRCodeDataMode.Auto
qr.QRCodeECL = QRCodeECL.H ' H-level error correction required for logo overlay
Dim qrImage As Image = qr.drawBarcode()
Using g As Graphics = Graphics.FromImage(qrImage)
Dim logo As Image = Image.FromFile("brand-logo.png")
Dim logoSize As Integer = qrImage.Width \ 5
Dim x As Integer = (qrImage.Width - logoSize) \ 2
Dim y As Integer = (qrImage.Height - logoSize) \ 2
g.DrawImage(logo, x, y, logoSize, logoSize)
End Using
qrImage.Save("product-qr.png")
IronBarcode 方法:
using IronBarCode;
var qr = QRCodeWriter.CreateQrCodeWithLogo("https://example.com/product/4891", "brand-logo.png", 500);
qr.SaveAsPng("product-qr.png");
using IronBarCode;
var qr = QRCodeWriter.CreateQrCodeWithLogo("https://example.com/product/4891", "brand-logo.png", 500);
qr.SaveAsPng("product-qr.png");
Imports IronBarCode
Dim qr = QRCodeWriter.CreateQrCodeWithLogo("https://example.com/product/4891", "brand-logo.png", 500)
qr.SaveAsPng("product-qr.png")
錯誤更正級別、Logo尺寸計算和圖像組合在內部處理。 不需要System.Drawing依賴。
從圖像中讀取條碼
從圖像文件讀取最清楚地說明了產品整合。 使用OnBarcode時,讀取需要單獨的Reader SDK,一個單獨的授權調用,以及明確的格式規範。 使用IronBarcode,它是一個單一的靜態調用,使用已經到位的相同包和鍵。
OnBarcode方法:
using OnBarcode.Barcode;
// OnBarcode reader is distributed as a pre-licensed DLL — no runtime SetLicense() call.
BarcodeScanner scanner = new BarcodeScanner();
scanner.BarcodeTypes = new BarcodeType[] { BarcodeType.Code128, BarcodeType.QRCode };
string[] results = scanner.Scan("received-label.png");
foreach (string value in results)
Console.WriteLine(value);
using OnBarcode.Barcode;
// OnBarcode reader is distributed as a pre-licensed DLL — no runtime SetLicense() call.
BarcodeScanner scanner = new BarcodeScanner();
scanner.BarcodeTypes = new BarcodeType[] { BarcodeType.Code128, BarcodeType.QRCode };
string[] results = scanner.Scan("received-label.png");
foreach (string value in results)
Console.WriteLine(value);
Imports OnBarcode.Barcode
' OnBarcode reader is distributed as a pre-licensed DLL — no runtime SetLicense() call.
Dim scanner As New BarcodeScanner()
scanner.BarcodeTypes = New BarcodeType() {BarcodeType.Code128, BarcodeType.QRCode}
Dim results As String() = scanner.Scan("received-label.png")
For Each value As String In results
Console.WriteLine(value)
Next
IronBarcode 方法:
using IronBarCode;
var results = BarcodeReader.Read("received-label.png");
foreach (var result in results)
Console.WriteLine($"{result.Format}: {result.Value}");
using IronBarCode;
var results = BarcodeReader.Read("received-label.png");
foreach (var result in results)
Console.WriteLine($"{result.Format}: {result.Value}");
Imports IronBarCode
Dim results = BarcodeReader.Read("received-label.png")
For Each result In results
Console.WriteLine($"{result.Format}: {result.Value}")
Next
不需要實例建立、不需要格式陣列、不需要單獨的授權配置。 格式是自動檢測的。 每個結果都帶有解碼值和檢測格式。 有關讀取選項和支援的圖像型別的詳細資訊,請參閱指南如何從圖像讀取條碼。
從PDF中讀取條碼
此遷移範例適用於先前使用第三方庫將PDF頁面呈現為圖像,然後將這些圖像傳遞給OnBarcode Reader SDK的團隊。
OnBarcode方法:
// OnBarcode has no native PDF support.
// A separate PDF rendering library was required — for example PdfiumViewer or Aspose.PDF.
var pageImages = RenderPdfPagesToImages("invoices.pdf"); // external library call
using OnBarcode.Barcode;
BarcodeScanner scanner = new BarcodeScanner();
scanner.BarcodeTypes = new BarcodeType[] { BarcodeType.Code128, BarcodeType.QRCode };
foreach (var pageImage in pageImages)
{
string[] results = scanner.Scan(pageImage);
foreach (string value in results)
Console.WriteLine(value);
}
// OnBarcode has no native PDF support.
// A separate PDF rendering library was required — for example PdfiumViewer or Aspose.PDF.
var pageImages = RenderPdfPagesToImages("invoices.pdf"); // external library call
using OnBarcode.Barcode;
BarcodeScanner scanner = new BarcodeScanner();
scanner.BarcodeTypes = new BarcodeType[] { BarcodeType.Code128, BarcodeType.QRCode };
foreach (var pageImage in pageImages)
{
string[] results = scanner.Scan(pageImage);
foreach (string value in results)
Console.WriteLine(value);
}
Imports OnBarcode.Barcode
' OnBarcode has no native PDF support.
' A separate PDF rendering library was required — for example PdfiumViewer or Aspose.PDF.
Dim pageImages = RenderPdfPagesToImages("invoices.pdf") ' external library call
Dim scanner As New BarcodeScanner()
scanner.BarcodeTypes = New BarcodeType() {BarcodeType.Code128, BarcodeType.QRCode}
For Each pageImage In pageImages
Dim results As String() = scanner.Scan(pageImage)
For Each value As String In results
Console.WriteLine(value)
Next
Next
IronBarcode 方法:
using IronBarCode;
var results = BarcodeReader.Read("invoices.pdf");
foreach (var result in results)
Console.WriteLine($"Page {result.PageNumber}: {result.Format} — {result.Value}");
using IronBarCode;
var results = BarcodeReader.Read("invoices.pdf");
foreach (var result in results)
Console.WriteLine($"Page {result.PageNumber}: {result.Format} — {result.Value}");
Imports IronBarCode
Dim results = BarcodeReader.Read("invoices.pdf")
For Each result In results
Console.WriteLine($"Page {result.PageNumber}: {result.Format} — {result.Value}")
Next
無需呈現步驟,無需外部PDF庫,無需格式陣列。 PDF條碼讀取功能會自動處理所有頁面,並在每個結果中包含頁碼。
批量生成
為一組項目生成條碼遵循與單次生成相同的模式差異。
OnBarcode方法:
using OnBarcode.Barcode;
foreach (var item in inventoryItems)
{
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE128;
barcode.Data = item.Sku;
barcode.Resolution = 96;
barcode.BarWidth = 1;
barcode.BarHeight = 80;
barcode.ShowText = true;
barcode.drawBarcode($"labels/{item.Id}.png");
}
using OnBarcode.Barcode;
foreach (var item in inventoryItems)
{
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE128;
barcode.Data = item.Sku;
barcode.Resolution = 96;
barcode.BarWidth = 1;
barcode.BarHeight = 80;
barcode.ShowText = true;
barcode.drawBarcode($"labels/{item.Id}.png");
}
Imports OnBarcode.Barcode
For Each item In inventoryItems
Dim barcode As New Linear()
barcode.Type = BarcodeType.CODE128
barcode.Data = item.Sku
barcode.Resolution = 96
barcode.BarWidth = 1
barcode.BarHeight = 80
barcode.ShowText = True
barcode.drawBarcode($"labels/{item.Id}.png")
Next
IronBarcode 方法:
using IronBarCode;
foreach (var item in inventoryItems)
{
BarcodeWriter.CreateBarcode(item.Sku, BarcodeEncoding.Code128)
.SaveAsPng($"labels/{item.Id}.png");
}
using IronBarCode;
foreach (var item in inventoryItems)
{
BarcodeWriter.CreateBarcode(item.Sku, BarcodeEncoding.Code128)
.SaveAsPng($"labels/{item.Id}.png");
}
Imports IronBarCode
For Each item In inventoryItems
BarcodeWriter.CreateBarcode(item.Sku, BarcodeEncoding.Code128) _
.SaveAsPng($"labels/{item.Id}.png")
Next
OnBarcode API到IronBarcode映射參考
| OnBarcode | IronBarcode | 注意事項 |
|---|---|---|
| 預先授權DLL(無運行時鍵調用) | IronBarCode.License.LicenseKey = "key" |
屬性分配; 在啟動時調用一次 |
| 兩個DLL引用(生成器+讀取器) | 單一 NuGet 套件 | 一個包覆蓋所有功能 |
new Linear() |
BarcodeWriter.CreateBarcode(data, encoding) |
靜態工廠; 無物件實例 |
barcode.BarcodeType = BarcodeType.CODE128 |
BarcodeEncoding.Code128作為參數 |
作為第二個參數傳遞給CreateBarcode |
barcode.Data = "..." |
CreateBarcode的第一個參數 |
資料是第一個參數 |
barcode.drawBarcode("file.png") |
.SaveAsPng("file.png") |
格式命名的方法 |
barcode.drawBarcode("file.jpg") |
.SaveAsJpeg("file.jpg") |
格式命名的方法 |
barcode.drawBarcode("file.pdf") |
.SaveAsPdf("file.pdf") |
本地PDF輸出 |
BarcodeType.CODE128 |
BarcodeEncoding.Code128 |
常數重命名 |
BarcodeType.QRCode |
BarcodeEncoding.QRCode |
直接映射 |
BarcodeType.EAN13 |
BarcodeEncoding.EAN13 |
直接映射 |
BarcodeType.DataMatrix |
BarcodeEncoding.DataMatrix |
直接映射 |
BarcodeType.PDF417 |
BarcodeEncoding.PDF417 |
直接映射 |
new BarcodeScanner() { BarcodeTypes = [...] } |
BarcodeReader.Read(path) — 靜態 |
無實例,無格式規範 |
scanner.Scan("file.png") → string[] |
BarcodeReader.Read("file.png") → BarcodeResults |
更豐富的返回型別 |
results[0](原始字串) |
result.Value |
解碼的字串值 |
| N/A | result.Format |
檢測格式 — 在OnBarcode中不可用 |
| N/A | result.PageNumber |
PDF讀取的頁面來源 |
| N/A | BarcodeReader.Read("document.pdf") |
本地PDF讀取; 無OnBarcode對應 |
| 用於QR標誌的手動GDI+覆蓋 | QRCodeWriter.CreateQrCodeWithLogo() |
內建的標誌支援 |
BarcodeType[]配置 |
不需要 | 自動檢測是預設的 |
常見遷移問題及解決方案
問題1:DLL引用衝突
OnBarcode: 繼承DLL發佈的項目有lib\OnBarcode.Barcode.dll或類似路徑。 如果在新增IronBarcode時舊DLL仍在磁盤上,編譯器將看到兩個提供相同命名空間前綴的程式集,並產生模糊的引用錯誤。
解決方案: 在運行<ItemGroup>引用塊。 從磁盤上刪除DLL文件。 使用乾淨的構建驗證是否沒有舊的程式集引用保留。
# Search for lingering OnBarcode DLL references in project files
grep -r "OnBarcode" --include="*.csproj" .
grep -r "OnBarcode" --include="*.props" .
# Search for lingering OnBarcode DLL references in project files
grep -r "OnBarcode" --include="*.csproj" .
grep -r "OnBarcode" --include="*.props" .
問題2:漸進遷移期間的類名衝突
OnBarcode: 閱讀器命名空間導出了一個名為BarcodeScanner的類。 IronBarcode有一個靜態類名為BarcodeReader。 這些名稱不會直接衝突,但任何同時導入BarcodeEncoding。 在遷移期間保持兩個命名空間的活動會在任何BarcodeType引用上產生編譯錯誤。
解決方案: 原子地完成每個文件的遷移——在同一編輯中移除using IronBarCode。 不要在任何文件中同時保留兩個using指令。如果需要分階段的方法,請臨時使用完全限定名稱:
// Temporary disambiguation during phased migration
var results = IronBarCode.BarcodeReader.Read("file.png");
// Temporary disambiguation during phased migration
var results = IronBarCode.BarcodeReader.Read("file.png");
' Temporary disambiguation during phased migration
Dim results = IronBarCode.BarcodeReader.Read("file.png")
問題3:BarcodeType陣列移除
OnBarcode: 閱讀器需要reader.BarcodeTypes = new BarcodeType[] { ... }才能運行。 遷移閱讀器程式碼的開發者有時會保持顯式指定格式的習慣,並在IronBarcode中尋找等效配置。
解決方案: 完全移除格式規範。 BarcodeReader.Read在所有支援的格式中自動檢測。 不需要配置,因為在IronBarcode中沒有BarcodeType[]的等效項。
// No format configuration required
var results = BarcodeReader.Read("label.png");
// No format configuration required
var results = BarcodeReader.Read("label.png");
Dim results = BarcodeReader.Read("label.png")
OnBarcode遷移清單
遷移前任務
在進行更改之前,審核程式碼庫以找到所有OnBarcode使用:
# Find all OnBarcode namespace imports
grep -rn "using OnBarcode" --include="*.cs" .
# Find all license configuration calls
grep -rn "SetLicense" --include="*.cs" .
# Find all generator usage
grep -rn "new Linear\|new QRCode\|drawBarcode\|BarcodeType\." --include="*.cs" .
# Find all reader usage
grep -rn "BarcodeScanner\|\.Scan(\|BarcodeType\[\]" --include="*.cs" .
# Find DLL references in project files
grep -rn "OnBarcode" --include="*.csproj" .
grep -rn "OnBarcode" --include="*.sln" .
# Find all OnBarcode namespace imports
grep -rn "using OnBarcode" --include="*.cs" .
# Find all license configuration calls
grep -rn "SetLicense" --include="*.cs" .
# Find all generator usage
grep -rn "new Linear\|new QRCode\|drawBarcode\|BarcodeType\." --include="*.cs" .
# Find all reader usage
grep -rn "BarcodeScanner\|\.Scan(\|BarcodeType\[\]" --include="*.cs" .
# Find DLL references in project files
grep -rn "OnBarcode" --include="*.csproj" .
grep -rn "OnBarcode" --include="*.sln" .
記錄哪些文件僅使用生成,哪些使用讀取,哪些同時使用。 注意包含手動<Reference> DLL塊而不是NuGet包引用的任何文件。
程式碼更新任務
- 移除
OnBarcode.Barcode.GeneratorNuGet包 - 移除
OnBarcode.Barcode.ReaderNuGet包 - 從
<Reference>DLL條目 - 從儲存庫中刪除OnBarcode DLL文件
- 運行
dotnet add package IronBarcode - 在每個文件中用
using OnBarcode.Barcode - 在每個文件中用
using OnBarcode.Barcode.Reader - 移除兩個OnBarcode DLL
<Reference>條目(生成器和讀取器)—無需替換運行時授權調用 - 在應用啟動時新增
IronBarCode.License.LicenseKey = "YOUR-KEY"一次 - 將每個
new QRCode()+ 屬性分配塊轉換為BarcodeWriter.CreateBarcode(data, encoding) - 我用
barcode.drawBarcode("file.png") - 用
new BarcodeScanner() { BarcodeTypes = [...] }+.Scan(path) - 將結果處理從
BarcodeResults上 - 移除任何用於解決OnBarcode的PDF限制的PDF到圖像呈現程式碼
- 用單一
BarcodeReader.Read("file.pdf")調用替換多步驟PDF呈現+掃描迴圈
遷移後測試
驗證項目中使用的每種條碼型別(程式碼128、QR、EAN、資料矩陣、PDF417)生成可掃描的輸出
用實體掃描儀或移動裝置掃描生成的條碼以確認可讀性
驗證條碼讀取對已知的測試圖像返回正確的值
確認PDF讀取對多頁測試文件返回正確的值和正確的頁碼
通過任何CI環境運行應用以確認授權鍵配置在管道中正確工作
檢查.csproj或配置文件中
遷移到IronBarcode的主要優勢
合併的包和授權: 遷移後,一個NuGet包和一個授權鍵涵蓋所有條碼操作。 沒有需要採購的獨立產品,沒有需要跟蹤的獨立版本計劃,並且沒有需要在啟動時維護的雙授權配置。兩個產品安排的複雜性被一個單一的依賴替代。
透明採購: IronBarcode在產品網站上發布永久授權層級和價格。組織可以確定總成本,提交採購訂單,並在沒有銷售對話的情況下完成採購。 IronBarcode授權頁面包括所有層級的定價和用於Docker和雲環境的密鑰配置詳細資訊。
本地PDF支援: 以前需要一個單獨的PDF呈現庫來處理嵌入條碼的PDF的項目可以完全消除該依賴。 單一BarcodeReader.Read調用無需任何呈現步驟即可處理PDF文件的所有頁面,每個結果都包括其被提取的頁碼。
更豐富的閱讀結果:BarcodeResults返回型別提供了解碼值、檢測的條碼格式、源圖像中的邊界框坐標和PDF閱讀的頁碼。 以前處理平面string[]的應用現在可以顯示格式資訊,支援註釋工作流程或實施基於信心水平的過濾,而無需額外的處理。
減少的API表面: 靜態工廠模式取代了屬性分配模型。 常見的生成操作需要減少程式碼行,而讀取操作不需要建立實例或格式預配置。 批量操作從更小的每個項目程式碼腳本中受益,隨著時間的推移更易於審查和維護。
常見問題
我為什麼應該從OnBarcode遷移到IronBarcode?
常見的理由包括簡化授權(去除SDK +運行時鑰匙的複雜性)、消除吞吐量限制、獲得原生PDF支持、改善Docker/CI/CD部署,並減少生產程式碼中的API樣板。
我該如何使用IronBarcode替換OnBarcode API呼叫?
用IronBarCode.License.LicenseKey = "key"替換實例建立和授權樣板。用BarcodeReader.Read(path)替換讀取呼叫,用BarcodeWriter.CreateBarcode(data, encoding)替換寫入呼叫。靜態方法不需要實例管理。
從OnBarcode遷移到IronBarcode需要更改多少程式碼?
大多數遷移會導致較少的程式碼行。授權樣板、實例構造函式和顯式格式配置被移除。核心讀/寫操作映射為較短的IronBarcode等價物,且結果物件更清晰。
在遷移期間,我需要同時安裝OnBarcode和IronBarcode嗎?
不需要。大多數遷移是直接替換而不是並行操作。一次遷移一個服務類,替換NuGet引用,並更新實例化和API呼叫模式後再移動到下一個類。
IronBarcode的NuGet包名稱是什麼?
包名是'IronBarCode'(大寫B和C)。可以用'Install-Package IronBarCode'或'dotnet add package IronBarCode'安裝。程式碼中的using指令是'using IronBarCode;'。
與OnBarcode相比,IronBarcode如何簡化Docker部署?
IronBarcode是沒有外部SDK文件或掛載許可配置的NuGet封裝。在Docker中,設置IRONBARCODE_LICENSE_KEY環境變數,包在啟動時處理許可驗證。
從OnBarcode遷移後,IronBarcode是否能自動檢測所有條碼格式?
是的。IronBarcode自動檢測所有支持的格式的符號學。不需要顯式的BarcodeTypes枚舉。如果格式已經知道並且性能很重要,BarcodeReaderOptions允許限制搜索空間作為優化。
IronBarcode是否可以不使用單獨的庫讀取PDF中的條碼?
可以。BarcodeReader.Read("document.pdf")原生處理PDF文件。結果包括每個條碼發現的頁碼、格式、值和置信度。不需要外部PDF渲染步驟。
IronBarcode如何處理並行條碼處理?
IronBarcode的靜態方法是無狀態且執行緒安全的。直接使用Parallel.ForEach遍歷文件列表,不需要每個執行緒的實例管理。BarcodeReaderOptions.MaxParallelThreads控制內部執行緒預算。
從OnBarcode遷移到IronBarcode時,哪些結果屬性會更改?
常見的重命名:BarcodeValue變為Value,BarcodeType變為Format。IronBarcode結果還新增了Confidence和PageNumber。整個解決方案的搜索和替換可處理現有結果處理程式碼中的重新命名。
我如何在CI/CD管道中設置IronBarcode授權?
將IRONBARCODE_LICENSE_KEY作為管道機密儲存,在應用程式啟動程式碼中分配IronBarCode.License.LicenseKey。一個機密涵蓋所有環境,包括開發、測試、分期和生產。
IronBarcode是否支持生成帶有自定義樣式的QR碼?
支持。QRCodeWriter.CreateQrCode()支持通過ChangeBarCodeColor()自定義顏色,通過AddBrandLogo()嵌入logo,可配置錯誤校正級別,以及包括PNG、JPG、PDF和流在內的多種輸出格式。

