Aspose.BarCode for .NET 與 IronBarcode:C# 條碼庫比較
每個使用過 Aspose.BarCode 的開發者都曾經寫過類似這樣的程式碼行:new BarCodeReader(path, DecodeType.Code128)。 如果你知道影像的格式,它就能正常運作。 當你沒有這樣做時——當文件來自外部系統、更改了標籤格式的供應商或用戶上傳時——你要么猜測解碼類型列表,要么使用 DecodeType.AllSupportedTypes,這明顯慢得多。 格式規範要求雖然不是致命缺陷,但它會在程式碼庫的每次讀取操作中累積,造成日常摩擦。
PDF文件講述的是預算故事。 如果您要處理 PDF 文件中的條碼,Aspose.BarCode 無法單獨完成這項工作。 您需要 Aspose.PDF for .NET 來先將頁面渲染成影像。 Aspose.PDF 是另一項訂閱服務:每年 999 美元到 4,995 美元不等,這還不包括您已支付的 Aspose.BarCode 費用。 對大多數開發者來說,這明明是一個任務,卻需要兩個訂閱才能完成。
IronBarcode 能夠自動偵測條碼格式,在一個軟體包中原生讀取 PDF 文件,並提供起價 749 美元的永久許可證。本文將詳細比較這兩個庫,以便您做出明智的選擇。
了解 Aspose.BarCode
多年來,Aspose 一直致力於為 .NET、Java 和其他平台建立文件處理庫。 Aspose.BarCode 是該系列眾多產品之一,其他產品包括 Aspose.Words、Aspose.Cells、Aspose.PDF、Aspose.Slides 以及其他十幾個產品。 對於已經付費使用 Aspose.Total(包含所有 Aspose 產品)的團隊來說,Aspose.BarCode 無需額外費用。但對於只需要條碼庫的團隊而言,訂閱模式的合理性就難以體現了。
Aspose.BarCode 支援 60 多種條碼符號體系,是所有商業 .NET 條碼庫中最完整的格式清單。 館藏的廣度是圖書館最大的賣點。 API介面相應地很大,且API的詳細程度會隨著功能的增加而增加。 產生基本的 Code 128 條碼需要實例化 BarcodeGenerator,設定 XDimension、BarHeight 和其他參數,然後使用明確格式參數呼叫 Save。 讀取需要指定要搜尋的解碼類型,呼叫 ReadBarCodes(),然後迭代 FoundBarCodes。 這兩個操作都能正常運作──只是比實際需要的要冗長一些。
Aspose.BarCode 的主要架構特點:
-格式優先讀取模型:每次讀取操作都需要明確指定 DecodeType。 回退方案 DecodeType.AllSupportedTypes 比目標清單慢得多,因為解碼器會依序運行每個已知的符號系統。
-基於實例的 API: BarCodeReader 和 BarcodeGenerator 都是實作了 IDisposable 的實例化物件。 如果不將它們包裹在 using 程式碼區塊中,會導致資源洩漏。
-不支援原生 PDF: Aspose.BarCode 無法直接開啟或渲染 PDF 文件。 從 PDF 讀取條碼需要 Aspose.PDF,這是一個單獨的訂閱產品,每年價格為 999 美元至 4,995 美元。
-深度參數層次結構:自訂是透過 generator.Parameters.Barcode.* 屬性鏈處理的-這是一個需要記憶的多層物件層次結構。
-僅限訂閱許可:所有級別均為年度訂閱。 目前沒有單獨提供永久授權選項。
-基於文件的許可證啟動:生產部署需要一個位於已知路徑的 .lic 文件,這為Docker和 Kubernetes 環境增加了一個部署步驟。
格式優先閱讀模式
Aspose.BarCode 的讀取 API 的設計前提是呼叫者知道條碼格式:
// Aspose.BarCode: must specify format or use slow AllSupportedTypes
using Aspose.BarCode.BarCodeRecognition;
var reader = new BarCodeReader("barcode.png", DecodeType.Code128);
reader.ReadBarCodes();
foreach (var result in reader.FoundBarCodes)
Console.WriteLine($"{result.CodeTypeName}: {result.CodeText}");
// Aspose.BarCode: must specify format or use slow AllSupportedTypes
using Aspose.BarCode.BarCodeRecognition;
var reader = new BarCodeReader("barcode.png", DecodeType.Code128);
reader.ReadBarCodes();
foreach (var result in reader.FoundBarCodes)
Console.WriteLine($"{result.CodeTypeName}: {result.CodeText}");
Imports Aspose.BarCode.BarCodeRecognition
' Aspose.BarCode: must specify format or use slow AllSupportedTypes
Dim reader As New BarCodeReader("barcode.png", DecodeType.Code128)
reader.ReadBarCodes()
For Each result In reader.FoundBarCodes
Console.WriteLine($"{result.CodeTypeName}: {result.CodeText}")
Next
如果你知道條碼格式,這種模式就沒問題。問題就在於"如果你知道條碼格式"。處理供應商發票的採購系統無法保證每個供應商都使用同一種條碼類型。 接受使用者上傳的文件管理系統無法預測掃描器所使用的格式。 在這種情況下,DecodeType.AllSupportedTypes 是備用方案,它比有針對性的解碼類型清單慢得多。
解碼器也必須被丟棄:
using var reader = new BarCodeReader("barcode.png", DecodeType.Code128);
using var reader = new BarCodeReader("barcode.png", DecodeType.Code128);
不使用 using 會導致資源外洩。 BarcodeGenerator 也實現了 IDisposable,儘管不釋放它的後果不太嚴重。 在這兩種情況下,您都在管理物件生命週期,而靜態工廠 API 會自動處理這些生命週期。
了解 IronBarcode
IronBarcode 使用靜態工廠方法進行讀取和寫入。 沒有實例可以建構、配置或釋放。 預設情況下,讀取 API 與格式無關,無論原始檔案是 PNG、JPEG、TIFF 還是 PDF,相同的呼叫都能正常運作。
IronBarcode 由 Iron Software 開發和維護,該公司專注於 .NET 開發人員工具。 該函式庫的設計原則是,條碼讀取不應該需要事先了解條碼格式-該函式庫的偵測引擎會根據影像內容確定格式。 對於生成過程,流暢的方法鏈取代了其他庫中常見的多層參數層次結構。
IronBarcode的主要特點:
-自動格式偵測: BarcodeReader.Read() 從影像內容辨識條碼符號,而無需呼叫者指定 DecodeType 等效項。
-靜態無狀態 API:所有讀寫操作均為靜態方法。 無需管理一次性實例,且 API 自然是執行緒安全的,可同時使用。
-原生 PDF 支援: BarcodeReader.Read("doc.pdf") 直接讀取 PDF 文件,無需任何額外的打包或渲染步驟。結果包括 result.PageNumber。
- Fluent Generation API:
BarcodeWriter.CreateBarcode()傳回一個可鍊式物件。 自訂功能使用方法鏈而不是屬性層次結構。 -永久授權模式:所有等級均提供一次性購買,無需每年續約。 -基於字串的許可證啟動:許可證金鑰透過IronBarCode.License.LicenseKey設置,與環境變數和 CI/CD 金鑰管理器相容。
功能比較
| 特點 | Aspose.BarCode | IronBarcode |
|---|---|---|
| 格式檢測 | 手動 — 必須指定 DecodeType 或使用慢速的 AllSupportedTypes |
所有支援的格式均自動運行 |
| 符號計數 | 60歲以上 | 50歲以上 |
| PDF 支援 | 不支援原生功能-需要單獨的 Aspose.PDF 許可證 | Native — BarcodeReader.Read("doc.pdf") 內建於軟體包中 |
| 定價模式 | 訂閱價格:999美元至4995美元/年 | 永久使用權,一次性付款 749 美元起 |
| 永久許可 | 無法提供 | 是的,所有級別 |
| API 風格 | 基於實例的詳細配置 | 靜態工廠方法,流暢 API |
| 一次性要求 | 是的——BarCodeReader 和 BarcodeGenerator |
否——無狀態靜態方法 |
| 線程安全 | 每個執行緒需要單獨的實例 | 無狀態-自然可安全用於並發使用 |
詳細功能比較
| 特點 | Aspose.BarCode | IronBarcode |
|---|---|---|
| 世代 | ||
| API 風格 | new BarcodeGenerator(EncodeTypes.X, "data") |
BarcodeWriter.CreateBarcode("data", BarcodeEncoding.X) |
| 自訂模式 | generator.Parameters.Barcode.* 屬性層次結構 |
流暢的方法鏈(.ResizeTo(), .ChangeBarCodeColor()) |
| 帶有徽標的二維碼 | 產生後手動 GDI+ 疊加 | .AddBrandLogo("logo.png") 內置 |
| 輸出到位元組 | generator.GenerateBarCodeImage() |
.ToPngBinaryData() |
| 彩色條碼 | generator.Parameters.Barcode.BarColor |
.ChangeBarCodeColor(Color.X) |
| 閱讀 | ||
| 格式規範 | 必填 (DecodeType) |
無需 — 自動 |
| 未知格式回退 | DecodeType.AllSupportedTypes(慢) |
同樣的呼叫—無需備用模式 |
| 效能調校 | 12+ QualitySettings 參數 |
ReadingSpeed 枚舉 — 三級 |
| 免洗器 | 是的 — using var reader = new BarCodeReader(...) |
不——這是靜態調用,沒有物件需要釋放。 |
| 結果訪問 | reader.FoundBarCodes 在呼叫 ReadBarCodes() 之後 |
傳回值 BarcodeReader.Read() |
| 條碼值屬性 | result.CodeText |
result.Value |
| 格式名稱屬性 | result.CodeTypeName |
result.Format.ToString() |
| PDF 支援 | ||
| 原生 PDF 閱讀 | 無 | 是 |
| PDF檔案必需 | Aspose.PDF(每年額外收費 999 美元至 4,995 美元) | 無額外包裹 |
| 結果中的頁碼 | 不適用 | result.PageNumber |
| 授權 | ||
| 許可模式 | 僅限訂閱,每年續訂 | 永久購買,一次性購買 |
| 單一開發商 | 每年999美元 | 一次性 749 美元 |
| 10 位開發者 | 4,995美元/年(站點許可) | 一次性支付 2,999 美元(專業版) |
| 無限開發者 | 14,985 美元/年(OEM) | 一次性支付 5,999 美元(無限量) |
| 包含 PDF 支持 | 否-需單獨訂閱 Aspose.PDF。 | 是 |
| 平台和部署 | ||
| 許可證啟動 | .lic 檔案路徑 |
字串鍵 — 環境變數 |
| Docker部署 | 必須將 .lic 檔案複製到鏡像中或掛載它 |
環境變數-無需文件 |
| .NET Framework | 是 | 是的(4.6.2+) |
| .NET Core / .NET 5+ | 是 | 是的(.NET Core 3.1+,.NET 5/6/7/8/9) |
| 視窗 | 是 | 是的(x64/x86) |
| Linux | 是 | 是的(x64) |
| MacOS | 是 | 是的(x64/ARM) |
| Docker | 是 | 是 |
| Azure/AWS Lambda | 是 | 是 |
產生 API
在日常程式碼中,產生 API 最能體現這兩個函式庫在程式碼冗長程度上的差異。
Aspose.BarCode 方法
Aspose.BarCode 使用 BarcodeGenerator 類,並具有 Parameters 層次結構進行配置。 最小生成呼叫需要三個步驟-實例化、保存呼叫和格式規格。 實際使用通常需要導航到 generator.Parameters.Barcode.*:
using Aspose.BarCode.Generation;
using System.Drawing;
var generator = new BarcodeGenerator(EncodeTypes.Code128, "ITEM-12345");
// Common customizations require navigating a deep parameter hierarchy
generator.Parameters.Barcode.XDimension.Pixels = 2;
generator.Parameters.Barcode.BarHeight.Pixels = 100;
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below;
generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial";
generator.Parameters.Barcode.Padding.Left.Pixels = 10;
generator.Parameters.Barcode.Padding.Right.Pixels = 10;
generator.Parameters.BackColor = Color.White;
generator.Parameters.Resolution = 300;
generator.Save("barcode.png", BarCodeImageFormat.Png);
using Aspose.BarCode.Generation;
using System.Drawing;
var generator = new BarcodeGenerator(EncodeTypes.Code128, "ITEM-12345");
// Common customizations require navigating a deep parameter hierarchy
generator.Parameters.Barcode.XDimension.Pixels = 2;
generator.Parameters.Barcode.BarHeight.Pixels = 100;
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below;
generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial";
generator.Parameters.Barcode.Padding.Left.Pixels = 10;
generator.Parameters.Barcode.Padding.Right.Pixels = 10;
generator.Parameters.BackColor = Color.White;
generator.Parameters.Resolution = 300;
generator.Save("barcode.png", BarCodeImageFormat.Png);
Imports Aspose.BarCode.Generation
Imports System.Drawing
Dim generator As New BarcodeGenerator(EncodeTypes.Code128, "ITEM-12345")
' Common customizations require navigating a deep parameter hierarchy
generator.Parameters.Barcode.XDimension.Pixels = 2
generator.Parameters.Barcode.BarHeight.Pixels = 100
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.Below
generator.Parameters.Barcode.CodeTextParameters.Font.FamilyName = "Arial"
generator.Parameters.Barcode.Padding.Left.Pixels = 10
generator.Parameters.Barcode.Padding.Right.Pixels = 10
generator.Parameters.BackColor = Color.White
generator.Parameters.Resolution = 300
generator.Save("barcode.png", BarCodeImageFormat.Png)
每個自訂項目都會導覽至 generator.Parameters.Barcode.*,這是一個多層物件層次結構。 一旦記住了,就不複雜——但需要記憶。
IronBarcode方法
IronBarcode 將參數層次結構替換為流暢的方法鏈。 預設設定可滿足大多數使用場景的需求,自訂設定可直接在程式碼中表達:
using IronBarCode;
// Default settings work for most cases
BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128)
.SaveAsPng("barcode.png");
// Customization through a fluent chain
BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.SaveAsPng("barcode.png");
// Get as bytes instead of saving to disk
byte[] pngData = BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128)
.ToPngBinaryData();
using IronBarCode;
// Default settings work for most cases
BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128)
.SaveAsPng("barcode.png");
// Customization through a fluent chain
BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128)
.ResizeTo(400, 100)
.SaveAsPng("barcode.png");
// Get as bytes instead of saving to disk
byte[] pngData = BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128)
.ToPngBinaryData();
Imports IronBarCode
' Default settings work for most cases
BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128) _
.SaveAsPng("barcode.png")
' Customization through a fluent chain
BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128) _
.ResizeTo(400, 100) _
.SaveAsPng("barcode.png")
' Get as bytes instead of saving to disk
Dim pngData As Byte() = BarcodeWriter.CreateBarcode("ITEM-12345", BarcodeEncoding.Code128) _
.ToPngBinaryData()
對於二維碼, IronBarcode 的二維碼生成 API包含品牌徽標支持,無需手動合成圖像:
using IronBarCode;
using IronSoftware.Drawing;
// With brand logo — built in, no manual image overlay needed
QRCodeWriter.CreateQrCode("https://example.com", 500)
.AddBrandLogo("logo.png")
.SaveAsPng("qr-branded.png");
// With high error correction (recommended when using a logo)
QRCodeWriter.CreateQrCode(
"https://example.com",
500,
QRCodeWriter.QrErrorCorrectionLevel.Highest)
.AddBrandLogo("logo.png")
.SaveAsPng("qr-branded-high-ecc.png");
// Colored QR code
QRCodeWriter.CreateQrCode("https://example.com", 300)
.ChangeBarCodeColor(Color.DarkBlue)
.SaveAsPng("qr-colored.png");
using IronBarCode;
using IronSoftware.Drawing;
// With brand logo — built in, no manual image overlay needed
QRCodeWriter.CreateQrCode("https://example.com", 500)
.AddBrandLogo("logo.png")
.SaveAsPng("qr-branded.png");
// With high error correction (recommended when using a logo)
QRCodeWriter.CreateQrCode(
"https://example.com",
500,
QRCodeWriter.QrErrorCorrectionLevel.Highest)
.AddBrandLogo("logo.png")
.SaveAsPng("qr-branded-high-ecc.png");
// Colored QR code
QRCodeWriter.CreateQrCode("https://example.com", 300)
.ChangeBarCodeColor(Color.DarkBlue)
.SaveAsPng("qr-colored.png");
Imports IronBarCode
Imports IronSoftware.Drawing
' With brand logo — built in, no manual image overlay needed
QRCodeWriter.CreateQrCode("https://example.com", 500) _
.AddBrandLogo("logo.png") _
.SaveAsPng("qr-branded.png")
' With high error correction (recommended when using a logo)
QRCodeWriter.CreateQrCode( _
"https://example.com", _
500, _
QRCodeWriter.QrErrorCorrectionLevel.Highest) _
.AddBrandLogo("logo.png") _
.SaveAsPng("qr-branded-high-ecc.png")
' Colored QR code
QRCodeWriter.CreateQrCode("https://example.com", 300) _
.ChangeBarCodeColor(Color.DarkBlue) _
.SaveAsPng("qr-colored.png")
Aspose.BarCode 需要手動 GDI+ 繪圖才能將徽標疊加到二維碼上——生成條碼圖像,然後使用 System.Drawing.Graphics 將徽標合成到其中心。IronBarcode的 AddBrandLogo 只需一次呼叫即可處理該問題,並自動設定適當的糾正錯誤。
PDF條碼讀取
對許多團隊來說,這才是最重要的比較。從 PDF 文件中讀取條碼是常見的工作流程:例如,收到的發票、儲存為 PDF 格式的貨運標籤以及掃描的文件存檔。
Aspose.BarCode 方法
Aspose.BarCode 本身不支援 PDF。 要使用 Aspose 從 PDF 讀取條碼,您需要 Aspose.PDF 來載入 PDF 並將頁面渲染為影像,也需要 Aspose.BarCode 來掃描這些渲染後的影像。 兩者都是訂閱產品。 兩者都需要啟動許可證。 綜合起來,每年您需要花費 1,998 美元到 9,990 美元,而大多數開發人員認為這只是一項單一功能。
// Requires both Aspose.PDF (separate license) and Aspose.BarCode
using Aspose.Pdf;
using Aspose.Pdf.Devices;
using Aspose.BarCode.BarCodeRecognition;
using System.IO;
public List<string> ReadBarcodesFromPdf(string pdfPath)
{
var barcodeValues = new List<string>();
// Step 1: Load and render the PDF using Aspose.PDF
var pdfDocument = new Aspose.Pdf.Document(pdfPath);
var resolution = new Resolution(300);
var device = new PngDevice(resolution);
for (int pageNum = 1; pageNum <= pdfDocument.Pages.Count; pageNum++)
{
using var pageStream = new MemoryStream();
device.Process(pdfDocument.Pages[pageNum], pageStream);
pageStream.Seek(0, SeekOrigin.Begin);
// Step 2: Scan the rendered image for barcodes using Aspose.BarCode
using var reader = new BarCodeReader(pageStream, DecodeType.AllSupportedTypes);
foreach (var result in reader.ReadBarCodes())
{
barcodeValues.Add(result.CodeText);
}
}
return barcodeValues;
}
// Requires both Aspose.PDF (separate license) and Aspose.BarCode
using Aspose.Pdf;
using Aspose.Pdf.Devices;
using Aspose.BarCode.BarCodeRecognition;
using System.IO;
public List<string> ReadBarcodesFromPdf(string pdfPath)
{
var barcodeValues = new List<string>();
// Step 1: Load and render the PDF using Aspose.PDF
var pdfDocument = new Aspose.Pdf.Document(pdfPath);
var resolution = new Resolution(300);
var device = new PngDevice(resolution);
for (int pageNum = 1; pageNum <= pdfDocument.Pages.Count; pageNum++)
{
using var pageStream = new MemoryStream();
device.Process(pdfDocument.Pages[pageNum], pageStream);
pageStream.Seek(0, SeekOrigin.Begin);
// Step 2: Scan the rendered image for barcodes using Aspose.BarCode
using var reader = new BarCodeReader(pageStream, DecodeType.AllSupportedTypes);
foreach (var result in reader.ReadBarCodes())
{
barcodeValues.Add(result.CodeText);
}
}
return barcodeValues;
}
Imports Aspose.Pdf
Imports Aspose.Pdf.Devices
Imports Aspose.BarCode.BarCodeRecognition
Imports System.IO
Public Function ReadBarcodesFromPdf(pdfPath As String) As List(Of String)
Dim barcodeValues As New List(Of String)()
' Step 1: Load and render the PDF using Aspose.PDF
Dim pdfDocument As New Aspose.Pdf.Document(pdfPath)
Dim resolution As New Resolution(300)
Dim device As New PngDevice(resolution)
For pageNum As Integer = 1 To pdfDocument.Pages.Count
Using pageStream As New MemoryStream()
device.Process(pdfDocument.Pages(pageNum), pageStream)
pageStream.Seek(0, SeekOrigin.Begin)
' Step 2: Scan the rendered image for barcodes using Aspose.BarCode
Using reader As New BarCodeReader(pageStream, DecodeType.AllSupportedTypes)
For Each result In reader.ReadBarCodes()
barcodeValues.Add(result.CodeText)
Next
End Using
End Using
Next
Return barcodeValues
End Function
這涉及到兩套許可證設定、來自兩個命名空間的兩個 using 語句、渲染管線、記憶體流管理以及嵌套循環。此外,它還使用了 DecodeType.AllSupportedTypes,因為在影像擷取時,通常無法確定條碼的格式。
IronBarcode方法
IronBarcode 在內部處理 PDF 解析、頁面渲染和條碼偵測。 你呼叫 Read,路徑以 .pdf 結尾,它會回傳包含 result.PageNumber 的條碼結果,這樣你就知道每個結果來自哪個頁面。 沒有第二個軟體包,沒有第二個許可證,沒有渲染程式碼。
using IronBarCode;
public List<string> ReadBarcodesFromPdf(string pdfPath)
{
var results = BarcodeReader.Read(pdfPath);
return results.Select(r => r.Value).ToList();
}
using IronBarCode;
public List<string> ReadBarcodesFromPdf(string pdfPath)
{
var results = BarcodeReader.Read(pdfPath);
return results.Select(r => r.Value).ToList();
}
Imports IronBarCode
Public Function ReadBarcodesFromPdf(pdfPath As String) As List(Of String)
Dim results = BarcodeReader.Read(pdfPath)
Return results.Select(Function(r) r.Value).ToList()
End Function
// With page number context
var results = BarcodeReader.Read("invoice-batch.pdf");
foreach (var barcode in results)
{
Console.WriteLine($"Page {barcode.PageNumber}: [{barcode.Format}] {barcode.Value}");
}
// With page number context
var results = BarcodeReader.Read("invoice-batch.pdf");
foreach (var barcode in results)
{
Console.WriteLine($"Page {barcode.PageNumber}: [{barcode.Format}] {barcode.Value}");
}
Imports System
' With page number context
Dim results = BarcodeReader.Read("invoice-batch.pdf")
For Each barcode In results
Console.WriteLine($"Page {barcode.PageNumber}: [{barcode.Format}] {barcode.Value}")
Next
IronBarcode PDF 讀取文件涵蓋多頁批次處理和頁面範圍篩選選項。
讀取未知條碼格式
當您不知道圖像包含的條碼格式時,這兩個庫的處理方式截然不同。
Aspose.BarCode 方法
DecodeType.AllSupportedTypes 是 Aspose 針對格式未知情境的解。 Aspose 自己的文件也承認,這種方法比指定目標清單慢,因為解碼器會依序遍歷每個已知的符號系統。 對於大批量處理——例如倉庫每分鐘掃描數千個標籤——這種效能差異可不是微不足道的。
using Aspose.BarCode.BarCodeRecognition;
// AllSupportedTypes scans for every known format — significantly slower
using var reader = new BarCodeReader("unknown-format.png");
reader.SetBarCodeReadType(DecodeType.AllSupportedTypes);
foreach (var result in reader.ReadBarCodes())
{
Console.WriteLine($"{result.CodeTypeName}: {result.CodeText}");
}
using Aspose.BarCode.BarCodeRecognition;
// AllSupportedTypes scans for every known format — significantly slower
using var reader = new BarCodeReader("unknown-format.png");
reader.SetBarCodeReadType(DecodeType.AllSupportedTypes);
foreach (var result in reader.ReadBarCodes())
{
Console.WriteLine($"{result.CodeTypeName}: {result.CodeText}");
}
Imports Aspose.BarCode.BarCodeRecognition
' AllSupportedTypes scans for every known format — significantly slower
Using reader As New BarCodeReader("unknown-format.png")
reader.SetBarCodeReadType(DecodeType.AllSupportedTypes)
For Each result In reader.ReadBarCodes()
Console.WriteLine($"{result.CodeTypeName}: {result.CodeText}")
Next
End Using
IronBarcode方法
根據格式知識的不同,不存在"慢速模式"和"快速模式"。IronBarcode的偵測演算法與影像中包含 Code 128 或 DataMatrix 時所使用的演算法相同。 如果您想在效能和準確性之間進行權衡,可以使用 ReadingSpeed 選項,而無需了解格式:
using IronBarCode;
// The same call regardless of format — always auto-detects
var results = BarcodeReader.Read("unknown-format.png");
foreach (var result in results)
{
Console.WriteLine($"{result.Format}: {result.Value}");
}
using IronBarCode;
// The same call regardless of format — always auto-detects
var results = BarcodeReader.Read("unknown-format.png");
foreach (var result in results)
{
Console.WriteLine($"{result.Format}: {result.Value}");
}
Imports IronBarCode
' The same call regardless of format — always auto-detects
Dim results = BarcodeReader.Read("unknown-format.png")
For Each result In results
Console.WriteLine($"{result.Format}: {result.Value}")
Next
using IronBarCode;
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
MaxParallelThreads = 4
};
var results = BarcodeReader.Read("document.png", options);
using IronBarCode;
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
MaxParallelThreads = 4
};
var results = BarcodeReader.Read("document.png", options);
Imports IronBarCode
Dim options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True,
.MaxParallelThreads = 4
}
Dim results = BarcodeReader.Read("document.png", options)
ReadingSpeed.Faster 優先考慮吞吐量。 ReadingSpeed.Detailed 優先保證受損或低對比影像的準確性。 兩者都不需要你事先知道格式。 有關所有調優參數,請參閱IronBarcode 讀取選項。
API 對應參考。
| Aspose.BarCode | IronBarcode |
|---|---|
new BarCodeGenerator(EncodeTypes.Code128, "data") |
BarcodeWriter.CreateBarcode("data", BarcodeEncoding.Code128) |
generator.Save("file.png", BarCodeImageFormat.Png) |
.SaveAsPng("file.png") |
new BarCodeReader(path, DecodeType.Code128) |
BarcodeReader.Read(path) |
DecodeType.AllSupportedTypes(緩慢、徹底的掃描) |
自動-始終快速,所有格式均採用相同的呼叫方式 |
reader.ReadBarCodes() |
(part of BarcodeReader.Read — returns results directly) |
reader.FoundBarCodes |
傳回值 BarcodeReader.Read |
result.CodeText |
result.Value |
result.CodeTypeName |
result.Format.ToString() |
result.Confidence |
result.Confidence |
Aspose.BarCode + Aspose.PDF for PDF reading |
BarcodeReader.Read("doc.pdf") — 一個包裹 |
license.SetLicense("Aspose.BarCode.lic") |
IronBarCode.License.LicenseKey = "key" |
new Aspose.BarCode.Metered() + .SetMeteredKey() |
(not needed — single key covers all environments) |
generator.GenerateBarCodeImage() |
.ToPngBinaryData() 或 .SaveAsPng() |
QREncodeMode.Auto + QRErrorLevel.LevelH + 手動標誌疊加 |
QRCodeWriter.CreateQrCode().AddBrandLogo() |
當團隊考慮從 Aspose.BarCode 遷移到IronBarcode時
通常情況下,開發團隊會在多種情況下評估IronBarcode作為 Aspose.BarCode 的替代方案。
訂閱續費通知已到
年度訂閱續約是團隊最常重新檢視圖書館決策的時刻。 如果 Aspose.BarCode 是 Aspose 產品組合中唯一的產品,那麼每年 999 美元到 4995 美元的條碼功能價格就足以引發人們的比較。 對話通常是這樣的:"我們要永遠每年都支付這筆費用。"IronBarcode的一次性費用是多少?專業版(10 位開發人員 2,999 美元)的IronBarcode在第一年內即可透過站點許可收回成本。
對於使用 Aspose.Total 的團隊(其中 Aspose.BarCode 與 20 多個其他產品捆綁在一起),計算方法有所不同。 在該捆綁包中,Aspose.BarCode 的邊際成本接近零。 這些球隊就沒有太多理由做出改變。
PDF支援成為必要條件
許多專案最初都是從影像中讀取條碼,後來當利害關係人意識到傳入的文件是 PDF 而不是影像檔案時,才加入了 PDF 支援。 此時,Aspose.BarCode 團隊面臨一個決定:新增 Aspose.PDF(另一個訂閱),尋找第三方 PDF 渲染器,或重新評估條碼庫。
增加 Aspose.PDF 可以解決眼前的需求,但會使訂閱費用翻倍。尋找第三方渲染器則會增加依賴項和整合工作。 重新評估條碼庫,並發現IronBarcode只需一次性付費即可原生讀取 PDF,這通常是最終結果。
生產環境中格式未知的情況
接受文件上傳的面向客戶的應用程式無法控制上傳文件所使用的條碼格式。 如果應用程式是假設 Code 128 輸入而客戶上傳了 DataMatrix 標籤,則硬編碼的 DecodeType.Code128 將靜默地不傳回任何結果。 改為 DecodeType.AllSupportedTypes 可以修復正確性問題,但會帶來效能損失。
遇到此問題的團隊——隨著生產環境中出現新的格式,向其讀取器配置中添加越來越多的 DecodeType 值——最終往往需要維護一個列表,而每次添加新的格式來源時都需要更新該列表。IronBarcode的自動偵測功能使該清單變得不必要。
雲端和容器化部署
Aspose.BarCode 的檔案授權增加了一個部署步驟:許可證檔案必須在執行時可以從應用程式可以讀取的路徑存取。 在 GitOps 工作流程中,許可證檔案要麼最終進入原始碼控制(存在安全風險),要麼需要透過掛載的金鑰磁碟區注入。IronBarcode以金鑰為基礎的方法可以完美地融入 Kubernetes secrets 和 CI/CD secret 變數中,而無需在容器映像中管理任何檔案。
常見的遷移考量
從 Aspose.BarCode 過渡到IronBarcode的團隊會遇到一些可預見的技術調整。
屬性名稱映射
交換軟體套件後最常見的編譯錯誤是 result.CodeText 到 result.Value 的重新命名。 對整個程式碼庫進行搜尋可以快速解決這個問題:
grep -r "\.CodeText" --include="*.cs" .
grep -r "\.CodeTypeName" --include="*.cs" .
grep -r "\.CodeText" --include="*.cs" .
grep -r "\.CodeTypeName" --include="*.cs" .
result.CodeText 變為 result.Value。 result.CodeTypeName 變為 result.Format.ToString()。 result.Format 屬性是一個 BarcodeEncoding 枚舉值,它也允許在需要時進行類型比較。
解碼類型移除
程式碼庫中所有 DecodeType.* 引用都可以刪除:
grep -r "DecodeType\." --include="*.cs" .
grep -r "DecodeType\." --include="*.cs" .
如果列出了特定的 DecodeType 以提高已知格式的效能,則 ReadingSpeed.Faster 在 BarcodeReaderOptions 中提供類似的好處,而無需了解格式要求。
許可證初始化變更
Aspose.BarCode 使用透過 license.SetLicense() 載入的 .lic 檔案。IronBarcode使用字串鍵:
IronBarCode.License.LicenseKey =
Environment.GetEnvironmentVariable("IRONBARCODE_LICENSE")
?? throw new InvalidOperationException("IronBarcode license key not configured");
IronBarCode.License.LicenseKey =
Environment.GetEnvironmentVariable("IRONBARCODE_LICENSE")
?? throw new InvalidOperationException("IronBarcode license key not configured");
Imports IronBarCode
Imports System
License.LicenseKey = If(Environment.GetEnvironmentVariable("IRONBARCODE_LICENSE"), Throw New InvalidOperationException("IronBarcode license key not configured"))
從儲存庫中移除 .lic 檔案並建置工件。 在Docker中,刪除 COPY Aspose.BarCode.lic 行,並替換為 ENV IRONBARCODE_LICENSE 條目。
編碼類型到條碼編碼的映射
EncodeTypes.QR 對應到 BarcodeEncoding.QRCode — 命名差異是團隊在遷移產生程式碼後最常遇到的第一個編譯錯誤。 所有其他映射都是直接等效的,並且命名一致。
IronBarcode的其他功能
除了核心對比點之外,IronBarcode 還提供了一些可能與應用程式場景相關的功能:
-每張影像的多條碼偵測: ExpectMultipleBarcodes = true 傳回在單一影像中找到的所有條碼,以及每個條碼的位置座標。
-將條碼新增至 PDF :無需單獨的 PDF 庫,即可將條碼直接寫入現有的 PDF 頁面。
- TIFF 多幀讀取:一次呼叫即可讀取多頁 TIFF 中所有幀的條碼。 -樣式化的二維碼:顏色、徽標和糾錯級別均透過流暢的流程設置,無需外部圖像處理。
- Azure Functions 和 AWS Lambda 支援:標準授權支援在這兩個平台上進行無伺服器部署。 -二進位資料編碼:將位元組數組直接編碼為 Data Matrix 或 PDF417 條碼,用於二進位有效載荷用例。
.NET相容性與未來準備
IronBarcode 支援.NET Framework4.6.2+、.NET Core 3.1+ 以及 .NET 5、6、7、8 和 9。該程式庫會定期更新,與微軟的 .NET 發布節奏保持一致,確保與預計於 2026 年底發布的 .NET 10 相容。 Aspose.BarCode 也支援相同的 .NET 版本範圍,因此這兩個程式庫在目前版本上沒有相容性優勢。 對於未來的準備而言,真正重要的區別在於許可方式:今天購買的IronBarcode永久許可證可以涵蓋未來的 .NET 版本,無需額外費用,而 Aspose.BarCode 訂閱需要不斷續訂才能存取更新的版本。
結論
Aspose.BarCode 和IronBarcode代表了條碼庫設計中的兩種不同理念。 Aspose.BarCode 基於明確的、基於實例的 API 構建,呼叫者透過屬性層次結構指定格式、管理物件生命週期並配置每個操作。IronBarcode是基於靜態的、與格式無關的 API 構建,該庫在內部處理檢測、物件生命週期和 PDF 渲染。 兩種方法本身都沒有絕對的正確性——正確的選擇取決於應用程式的需求。
對於已經在 Aspose 生態系統中運作的團隊來說,Aspose.BarCode 是更強大的選擇。 如果 Aspose.Total 已經獲得許可,Aspose.BarCode 不會增加任何邊際成本,而且其 60 多個符號體系清單是任何商業 .NET 條碼庫中最廣泛的。 對於需要特殊格式(MaxiCode、DotCode 或IronBarcode50 多個清單中未包含的特定郵政符號)的應用,Aspose.BarCode 可能是唯一可行的選擇。 其成熟度和形式廣度是真正的優勢。
對於正在評估 Aspose.BarCode 是否值得單獨購買的團隊來說,其價值計算就比較困難了。 格式規格要求給每次讀取操作都帶來了不便。 由於缺少原生 PDF 支持,IronBarcode 的基本套餐中包含的此功能,其訂閱費用翻了一番。 訂閱模式意味著成本會逐年累積——一個 10 人開發團隊每年 4,995 美元,五年下來就是 24,975 美元,而一次性購買IronBarcodeProfessional 的價格為 2,999 美元。IronBarcode的自動偵測、原生 PDF 讀取和永久授權在一個軟體包中解決了所有這三個問題。
最終的決定取決於生態系的契合度和符號學的要求。 與 Aspose 產品深度整合的團隊,或需要IronBarcode支援清單之外的格式的團隊,應該使用 Aspose.BarCode。 對於需要獨立永久授權、原生 PDF 閱讀功能以及無需每次讀取都了解格式的 API 的團隊來說,IronBarcode 是更實用的選擇。
常見問題解答
什麼是適用於 .NET 的 Aspose.BarCode?
Aspose.BarCode for .NET 是一個 .NET 條碼庫,用於在 C# 應用程式中產生和讀取條碼。它是開發人員在為 .NET 專案選擇條碼解決方案時評估的幾個替代方案之一。
Aspose.BarCode for .NET 和 IronBarcode 的主要差異是什麼?
IronBarcode 使用靜態、無狀態的 API,無需實例管理,而 Aspose.BarCode for .NET 通常需要在使用前建立和設定實例。 IronBarcode 還提供原生 PDF 支援、自動格式偵測以及跨所有環境的單金鑰許可。
IronBarcode 的授權是否比 Aspose.BarCode for .NET 更容易?
IronBarcode 使用單一授權金鑰,同時涵蓋開發和生產部署。與將 SDK 金鑰與執行時間金鑰分開的授權系統相比,這簡化了 CI/CD 管線和 Docker 配置。
IronBarcode 是否支援 Aspose.BarCode for .NET 支援的所有條碼格式?
IronBarcode 支援超過 30 種條碼符號體系,包括 QR 碼、Code 128、Code 39、DataMatrix、PDF417、Aztec、EAN-13、UPC-A、GS1 等等。格式自動偵測功能意味著無需明確枚舉格式。
IronBarcode是否支援原生PDF條碼讀取?
是的。 IronBarcode 可以直接從 PDF 檔案讀取條碼,使用 `BarcodeReader.Read("document.pdf")` 方法,無需單獨的 PDF 渲染庫。每頁的讀取結果包括頁碼、條碼格式、數值和置信度評分。
與 Aspose.BarCode for .NET 相比,IronBarcode 在批次處理方面有何不同?
IronBarcode 的靜態方法是無狀態的,且天然執行緒安全,因此可以直接使用 Parallel.ForEach,而無需進行執行緒層級實例管理。所有定價層級均無吞吐量上限。
IronBarcode支援哪些.NET版本?
IronBarcode 在單一 NuGet 套件中支援 .NET Framework 4.6.2+、.NET Core 3.1 以及 .NET 5、6、7、8 和 9。平台目標包括 Windows x64/x86、Linux x64 和 macOS x64/ARM。
如何在.NET專案中安裝IronBarcode?
透過 NuGet 安裝 IronBarcode:在程式包管理器控制台中執行“Install-Package IronBarCode”,或在命令列介面中執行“dotnet add package IronBarCode”。無需其他 SDK 安裝程式或運行時檔案。
與 Aspose.BarCode 不同,我可以在購買前評估 IronBarcode 嗎?
是的。 IronBarcode 的試用模式會傳回完整的解碼條碼值-只有產生的輸出影像才會有浮水印。您可以在購買前,用自己的文件測試讀取準確率。
Aspose.BarCode for .NET 和 IronBarcode 的價格有什麼不同?
IronBarcode 的永久單開發者許可證起價為 749 美元,涵蓋開發和生產環境。定價詳情和大量許可選項請造訪 IronBarcode 授權頁面。無需單獨的運行時許可證。
從 Aspose.BarCode for .NET 遷移到 IronBarcode 是否簡單?
從 Aspose.BarCode for .NET 遷移到 IronBarcode 主要涉及將基於實例的 API 呼叫替換為 IronBarcode 的靜態方法、移除許可相關的樣板程式碼以及更新結果屬性名稱。大多數遷移都是減少程式碼,而不是增加程式碼。
IronBarcode 能產生帶有 logo 的二維碼嗎?
是的。 `QRCodeWriter.CreateQrCode().AddBrandLogo("logo.png")` 可以將品牌圖片原生嵌入二維碼中,並支援設定糾錯功能。此外,它還支援透過 `ChangeBarCodeColor()` 函數建立彩色二維碼。

