GrapeCity Barcode 与 IronBarcode:C# 条形码库对比
ComponentOne 的条形码控件可在 Windows Forms 应用程序内生成条形码。 它在这方面做得很好——API 简洁明了,输出质量可靠,并且可以与 WinForms 设计器自然地集成。 但它的作用范围很窄。 它无法读取条形码。 它无法在 Windows 系统之外运行。 而且它不是一个独立产品——它是 ComponentOne Studio Enterprise的一部分,该订阅服务价格约为 1,473 美元/开发人员/年,其中包括 100 多个适用于 WinForms、WPF、 Blazor和ASP.NET 的UI 控件。 如果您正在评估.NET项目的条形码选项,并且在比较列表中发现了 ComponentOne,那么本文将介绍该范围在实践中意味着什么。
了解 C1 条形码
C1BarCode 是一个 WinForms 可视化控件。 生成工作流创建一个实例,设置属性,并调用 GetImage() 来检索 System.Drawing.Image:
// ComponentOne C1BarCode
using C1.Win.C1BarCode;
using System.Drawing;
// License must be set before first use
C1.C1License.Key = "YOUR-COMPONENTONE-KEY";
var barcode = new C1BarCode();
barcode.CodeType = CodeType.Code128;
barcode.Text = "ITEM-12345";
barcode.BarHeight = 100;
barcode.ModuleSize = 2;
barcode.ShowText = true;
barcode.CaptionPosition = CaptionPosition.Below;
using var image = barcode.GetImage();
image.Save("barcode.png", System.Drawing.Imaging.ImageFormat.Png);
// ComponentOne C1BarCode
using C1.Win.C1BarCode;
using System.Drawing;
// License must be set before first use
C1.C1License.Key = "YOUR-COMPONENTONE-KEY";
var barcode = new C1BarCode();
barcode.CodeType = CodeType.Code128;
barcode.Text = "ITEM-12345";
barcode.BarHeight = 100;
barcode.ModuleSize = 2;
barcode.ShowText = true;
barcode.CaptionPosition = CaptionPosition.Below;
using var image = barcode.GetImage();
image.Save("barcode.png", System.Drawing.Imaging.ImageFormat.Png);
Imports C1.Win.C1BarCode
Imports System.Drawing
Imports System.Drawing.Imaging
' License must be set before first use
C1.C1License.Key = "YOUR-COMPONENTONE-KEY"
Dim barcode As New C1BarCode()
barcode.CodeType = CodeType.Code128
barcode.Text = "ITEM-12345"
barcode.BarHeight = 100
barcode.ModuleSize = 2
barcode.ShowText = True
barcode.CaptionPosition = CaptionPosition.Below
Using image As Image = barcode.GetImage()
image.Save("barcode.png", ImageFormat.Png)
End Using
WinForms 开发人员对属性设置器 API 并不陌生——它直接映射到设计器界面。 CodeType、BarHeight、ModuleSize、ShowText 和 CaptionPosition 都是设计器可见的属性,在代码中工作方式相同。
C1BarCode 支持主流的一维和二维条码格式:Code 39、Code 128、EAN-8、EAN-13、UPC-A、UPC-E、ITF、QR Code 和 PDF417 等。 它涵盖了 WinForms 生成中的常见用例。
无读取 API
这并非可以通过配置选项来弥补的缺陷。 没有 C1BarCodeReader 类。 在 C1BarCode 上没有 Decode() 方法。 ComponentOne 的条形码控件在设计上仅用于生成条形码。
如果您的应用程序需要扫描上传图像中的条形码、验证打印标签、处理带有嵌入式代码的文档,或者从 Web API 中的二维码提取数据——C1BarCode 都无法实现这些功能。 你需要一个单独的库来进行读取,这就引出了一个问题:既然独立的条形码库可以同时满足这两个操作,为什么还要为包含 100 多个控制功能的EnterpriseSuite中的一个仅用于生成条形码的组件付费呢?
对于设计用于打印输出的 WinForms 条形码控件来说,缺少读取 API 并不罕见。 当需求增加时,就会成为一个决策点——而条形码需求几乎总是会增加。
仅限 Windows 限制
C1BarCode 需要针对 Windows 系统的特定目标框架配置:
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<TargetFramework>net8.0-windows</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
net8.0-windows 目标框架别名和 UseWindowsForms 不是可选的首选项。 C1.Win.C1BarCode 依赖于 System.Windows.Forms 类型 — UserControl、PaintEventArgs、Graphics — 这些类型仅存在于 Windows 上。 移除 net8.0-windows 会导致构建失败。
相比之下,IronBarcode 的目标平台是 net8.0(或任何受支持的 TFM):
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
这在几个实际场景中都很重要:
- Azure App Service on Linux:新 App Service 部署的默认方案。 无法定位到
net8.0-windows。 - Docker 容器: Linux 容器是标准。 Windows 容器体积更大、成本更高,并且在许多云层级中不可用。
- ASP.NET Core Web API:只能部署到 Windows 的条形码生成端点是一个部署限制,团队最终需要将其移除。
- Azure Functions:消耗计划在 Linux 上运行。 目标为
net8.0-windows的条形码生成函数无法部署到消费计划。 - macOS 开发: macOS 上的开发者无法在本地运行
net8.0-windows项目,即使是测试生成逻辑也不行。
如果你的应用程序是一个WinForms桌面工具,并且只会在Windows上运行,那么平台限制就不是问题。 一旦部署要求包含任何 Linux 或云环境,问题就会出现。
Suite捆绑
C1BarCode 不是以独立NuGet包的形式提供的。 它是 ComponentOne Studio Enterprise的一部分,其中包括适用于 WinForms、WPF、 Blazor和ASP.NET的完整 ComponentOne 控件Suite。 ComponentOne Studio Enterprise的定价约为每位开发者每年 1,473 美元(订阅)。
该Suite包含 100 多个组件:网格、图表、日程安排程序、输入控件、报表设计器、地图控件、仪表等等。 如果您正在构建一个数据密集型的 WinForms 应用程序,并且需要很多这样的控件,那么Suite定价可能更划算。 如果您需要生成条形码,并且因为在搜索结果中看到了 ComponentOne 而找到了它,那么您购买的是一个大型EnterpriseUISuite,而它主要只是为了一个控件。
没有独立的 C1BarCode 软件包。 dotnet add package C1.Win.C1BarCode 不存在 — 该软件包是 C1.Win.C1BarCode,属于 GrapeCity.Documents 许可或 ComponentOne Studio 安装程序的一部分。 对于想要条形码功能但不需要完整Suite的开发者来说,没有部分购买选项。
IronBarcode 的定价结构有所不同:它是一个独立的条形码库,永久许可起价为 749 美元(适用于单个开发人员)。 没有网格控件,没有图表库,没有报表设计器——只有您正在寻找的条形码功能。
二维码定制
这两个库都支持生成二维码,并提供自定义选项。 API风格差异显著。
ComponentOne 属性设置器方法:
// ComponentOne — QR code with error correction and color
using C1.Win.C1BarCode;
using System.Drawing;
C1.C1License.Key = "YOUR-COMPONENTONE-KEY";
var barcode = new C1BarCode();
barcode.CodeType = CodeType.QRCode;
barcode.Text = "https://example.com/product/4821";
barcode.QRCodeVersion = QRCodeVersion.Version5;
barcode.QRCodeErrorCorrectionLevel = QRCodeErrorCorrectionLevel.High;
barcode.QRCodeModel = QRCodeModel.Model2;
barcode.ForeColor = Color.DarkBlue;
barcode.BackColor = Color.White;
barcode.ModuleSize = 4;
using var image = barcode.GetImage();
image.Save("product-qr.png", System.Drawing.Imaging.ImageFormat.Png);
// ComponentOne — QR code with error correction and color
using C1.Win.C1BarCode;
using System.Drawing;
C1.C1License.Key = "YOUR-COMPONENTONE-KEY";
var barcode = new C1BarCode();
barcode.CodeType = CodeType.QRCode;
barcode.Text = "https://example.com/product/4821";
barcode.QRCodeVersion = QRCodeVersion.Version5;
barcode.QRCodeErrorCorrectionLevel = QRCodeErrorCorrectionLevel.High;
barcode.QRCodeModel = QRCodeModel.Model2;
barcode.ForeColor = Color.DarkBlue;
barcode.BackColor = Color.White;
barcode.ModuleSize = 4;
using var image = barcode.GetImage();
image.Save("product-qr.png", System.Drawing.Imaging.ImageFormat.Png);
Imports C1.Win.C1BarCode
Imports System.Drawing
Imports System.Drawing.Imaging
C1.C1License.Key = "YOUR-COMPONENTONE-KEY"
Dim barcode As New C1BarCode()
barcode.CodeType = CodeType.QRCode
barcode.Text = "https://example.com/product/4821"
barcode.QRCodeVersion = QRCodeVersion.Version5
barcode.QRCodeErrorCorrectionLevel = QRCodeErrorCorrectionLevel.High
barcode.QRCodeModel = QRCodeModel.Model2
barcode.ForeColor = Color.DarkBlue
barcode.BackColor = Color.White
barcode.ModuleSize = 4
Using image As Image = barcode.GetImage()
image.Save("product-qr.png", ImageFormat.Png)
End Using
IronBarcode流畅链:
//IronBarcode— QR code with error correction and color
// NuGet: dotnet add package IronBarcode
using IronBarCode;
using System.Drawing;
QRCodeWriter.CreateQrCode(
"https://example.com/product/4821",
300,
QRCodeWriter.QrErrorCorrectionLevel.Highest)
.ChangeBarCodeColor(Color.DarkBlue)
.SaveAsPng("product-qr.png");
//IronBarcode— QR code with error correction and color
// NuGet: dotnet add package IronBarcode
using IronBarCode;
using System.Drawing;
QRCodeWriter.CreateQrCode(
"https://example.com/product/4821",
300,
QRCodeWriter.QrErrorCorrectionLevel.Highest)
.ChangeBarCodeColor(Color.DarkBlue)
.SaveAsPng("product-qr.png");
Imports IronBarCode
Imports System.Drawing
QRCodeWriter.CreateQrCode( _
"https://example.com/product/4821", _
300, _
QRCodeWriter.QrErrorCorrectionLevel.Highest) _
.ChangeBarCodeColor(Color.DarkBlue) _
.SaveAsPng("product-qr.png")
ComponentOne 方法需要实例化一个 C1BarCode 对象,并在调用 GetImage() 之前设置多个属性。IronBarcode的 QRCodeWriter 使用流畅的链式操作——每个操作都会返回条形码对象,最后调用 .SaveAsPng()。 没有需要管理的实例。
IronBarcode还支持在二维码中嵌入徽标,而 C1BarCode 则不支持:
// QR code with embedded brand logo
QRCodeWriter.CreateQrCode("https://example.com/track/8821", 500)
.AddBrandLogo("company-logo.png")
.ChangeBarCodeColor(Color.DarkBlue)
.SaveAsPng("branded-qr.png");
// QR code with embedded brand logo
QRCodeWriter.CreateQrCode("https://example.com/track/8821", 500)
.AddBrandLogo("company-logo.png")
.ChangeBarCodeColor(Color.DarkBlue)
.SaveAsPng("branded-qr.png");
' QR code with embedded brand logo
QRCodeWriter.CreateQrCode("https://example.com/track/8821", 500) _
.AddBrandLogo("company-logo.png") _
.ChangeBarCodeColor(Color.DarkBlue) _
.SaveAsPng("branded-qr.png")
了解IronBarcode
IronBarcode是一个独立的.NET条形码库,涵盖条形码的生成和读取。 它通过 NuGet 安装(dotnet add package IronBarcode),面向任何受支持的 .NET TFM,没有平台限制,并且可以在 Windows、Linux、macOS、Docker、Azure 和 AWS Lambda 上运行。
阅读方面原生支持PDF文档:
// Read barcodes from a PDF — no image extraction needed
using IronBarCode;
var results = BarcodeReader.Read("invoice.pdf");
foreach (var barcode in results)
{
Console.WriteLine($"Page {barcode.PageNumber}: {barcode.Format} — {barcode.Value}");
}
// Read barcodes from a PDF — no image extraction needed
using IronBarCode;
var results = BarcodeReader.Read("invoice.pdf");
foreach (var barcode in results)
{
Console.WriteLine($"Page {barcode.PageNumber}: {barcode.Format} — {barcode.Value}");
}
Imports IronBarCode
' Read barcodes from a PDF — no image extraction needed
Dim results = BarcodeReader.Read("invoice.pdf")
For Each barcode In results
Console.WriteLine($"Page {barcode.PageNumber}: {barcode.Format} — {barcode.Value}")
Next
对于高通量场景,BarcodeReaderOptions 控制速度与准确性之间的权衡以及多条形码检测:
// Multi-barcode read with performance options
using IronBarCode;
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
ExpectedBarcodeTypes = BarcodeEncoding.Code128 | BarcodeEncoding.QRCode
};
var results = BarcodeReader.Read("warehouse-manifest.jpg", options);
// Multi-barcode read with performance options
using IronBarCode;
var options = new BarcodeReaderOptions
{
Speed = ReadingSpeed.Balanced,
ExpectMultipleBarcodes = true,
ExpectedBarcodeTypes = BarcodeEncoding.Code128 | BarcodeEncoding.QRCode
};
var results = BarcodeReader.Read("warehouse-manifest.jpg", options);
Imports IronBarCode
' Multi-barcode read with performance options
Dim options As New BarcodeReaderOptions With {
.Speed = ReadingSpeed.Balanced,
.ExpectMultipleBarcodes = True,
.ExpectedBarcodeTypes = BarcodeEncoding.Code128 Or BarcodeEncoding.QRCode
}
Dim results = BarcodeReader.Read("warehouse-manifest.jpg", options)
生成功能涵盖标准格式,并提供一致的静态 API:
// Code 128 generation to file
BarcodeWriter.CreateBarcode("SHIP-20240312-7834", BarcodeEncoding.Code128)
.SaveAsPng("shipping-label.png");
// 二维码生成 to byte array (for HTTP response)
byte[] qrBytes = QRCodeWriter.CreateQrCode("https://example.com/order/7734", 400)
.ToPngBinaryData();
// Code 128 generation to file
BarcodeWriter.CreateBarcode("SHIP-20240312-7834", BarcodeEncoding.Code128)
.SaveAsPng("shipping-label.png");
// 二维码生成 to byte array (for HTTP response)
byte[] qrBytes = QRCodeWriter.CreateQrCode("https://example.com/order/7734", 400)
.ToPngBinaryData();
Imports System
' Code 128 generation to file
BarcodeWriter.CreateBarcode("SHIP-20240312-7834", BarcodeEncoding.Code128) _
.SaveAsPng("shipping-label.png")
' 二维码生成 to byte array (for HTTP response)
Dim qrBytes As Byte() = QRCodeWriter.CreateQrCode("https://example.com/order/7734", 400) _
.ToPngBinaryData()
支持的平台:Windows、Linux、macOS、Docker、Azure(应用服务和函数)、AWS Lambda。 支持的.NET版本: .NET 4.6.2 至.NET 9。
功能对比
| 特征 | GrapeCity C1条形码 | IronBarcode |
|---|---|---|
| 条形码生成 | 是 | 是 |
| 条形码读取 | 否 | 是 |
| 二维码生成 | 是 | 是 |
| 二维码标志嵌入 | 否 | 是 |
| 用于阅读的 PDF 输入 | 不适用(无读数) | 是的(母语) |
| .NET平台目标 | net8.0-windows 仅限 |
任何 TFM(net8.0 等) |
| 需要使用 Windows Forms。 | 是 | 否 |
| Linux/Docker部署 | 否 | 是 |
| macOS部署 | 否 | 是 |
| Azure Functions(Linux) | 否 | 是 |
| ASP.NET Core服务器端 | 有限(仅限 Windows 系统) | 是 |
| 独立NuGet包 | 否(仅限套件) | 是 |
| 独立定价 | 不适用 | 749 美元起永久 |
| Suite定价 | 约 1,473 美元/设备/年(订阅) | 不适用 |
| 流畅生成 API | 否(属性设置者) | 是 |
BarcodeReader.Read() |
否 | 是 |
BarcodeWriter.CreateBarcode() |
否 | 是 |
QRCodeWriter.CreateQrCode() |
否 | 是 |
| 支持的.NET版本 | .NET 6+(Windows) | .NET 4.6.2 至.NET 9 |
| 永久许可选项 | 无需订阅 | 是 |
API 映射参考
对于从 C1BarCode 迁移到IronBarcode 的团队,以下直接对应关系适用:
| ComponentOne C1条形码 | IronBarcode |
|---|---|
C1.C1License.Key = "..." |
IronBarCode.License.LicenseKey = "key" |
new C1BarCode() |
静态——无需实例 |
barcode.CodeType = CodeType.Code128 |
BarcodeEncoding.Code128(作为参数传递) |
barcode.Text = "data" |
BarcodeWriter.CreateBarcode() 的第一个参数 |
barcode.BarHeight = 100 |
条形码写入器上的 .ResizeTo(width, 100) |
barcode.ModuleSize = 2 |
.ResizeTo() 控制像素尺寸 |
barcode.ForeColor = Color.DarkBlue |
.ChangeBarCodeColor(Color.DarkBlue) |
barcode.BackColor = Color.White |
.ChangeBackgroundColor(Color.White) |
barcode.GetImage() |
.SaveAsPng() / .ToPngBinaryData() |
barcode.QRCodeErrorCorrectionLevel |
QRCodeWriter.QrErrorCorrectionLevel枚举 |
barcode.QRCodeVersion |
自动(或版本参数) |
| 无读取 API | BarcodeReader.Read(path) |
net8.0-windows 必填 |
net8.0(或任何 TFM) |
UseWindowsForms = true 必填 |
不要求 |
当球队切换
阅读需求出现了。这是最常见的触发因素。 一个团队使用 C1BarCode 构建条形码标签生成器,然后收到验证扫描、处理入库货运单据或解码上传图像中的二维码的需求。 C1BarCode 无法解决这个问题。有两种选择:要么添加第二个条形码读取库,要么用一个可以同时处理这两种情况的库替换 C1BarCode。
Linux 或 Docker 部署。而发布到 Windows 桌面的 WinForms 桌面应用程序则不受此限制。 生成条形码图像的ASP.NET Core API 确实如此——尤其是在需要在 Linux 容器中运行或部署到 Linux 上的 Azure 应用服务时。 net8.0-windows 目标框架立即阻止了这些部署选项。
微服务或无服务器架构。Azure Functions、AWS Lambda 和容器化微服务都优先考虑 Linux。无法部署到 Linux 的条形码生成服务不能称之为可行的微服务。
Suite订阅成本与需求范围。已经付费使用 ComponentOne Studio Enterprise并已在使用其网格、图表和其他控件的团队,已经证明了订阅的合理性。 主要或完全为了生成条形码而订阅的团队,正在为 100 多个他们没有使用的控件付费。 每个开发人员的订阅费用会随着团队规模的扩大而增加。
永久授权优先。ComponentOne Studio 仅提供订阅服务。 没有永久授权选项。 对于那些更喜欢拥有自己交付的软件的团队(特别是出于合规性或长期维护的原因),IronBarcode 的永久许可(起价 749 美元)在结构上有所不同。
结论
C1BarCode 能够在 WinForms 环境中干净利落地生成条形码。 这正是它真正擅长的,对于只需要在 Windows 上生成标签的 WinForms 桌面应用程序来说,它是 ComponentOneSuite中的一个功能性选择。
范围仅限于此。 不支持读取,仅限 Windows 部署,无独立软件包,采用订阅许可。 当一个项目的需求超出了在 Windows 上生成 WinForms 的范围时——例如阅读需求、Linux 部署目标、Web API、Docker 容器、云函数——C1BarCode 就无法满足这些需求了。 IronBarcode涵盖生成和读取功能,可在.NET支持的任何平台上运行,并且可以作为独立软件包使用,无需订阅包含 100 个控件的EnterpriseSuite。
常见问题解答
GrapeCity条形码是什么?
GrapeCity Barcode 是一个 .NET 条形码库,用于在 C# 应用程序中生成和读取条形码。它是开发人员在为 .NET 项目选择条形码解决方案时评估的几个备选方案之一。
GrapeCity Barcode 和 IronBarcode 的主要区别是什么?
IronBarcode 使用静态、无状态的 API,无需实例管理,而 GrapeCity Barcode 通常需要在使用前创建和配置实例。IronBarcode 还提供原生 PDF 支持、自动格式检测以及跨所有环境的单密钥许可。
IronBarcode 的授权比 GrapeCity Barcode 更容易吗?
IronBarcode 使用单一许可证密钥,同时涵盖开发和生产部署。与将 SDK 密钥与运行时密钥分开的许可系统相比,这简化了 CI/CD 流水线和 Docker 配置。
IronBarcode 是否支持 GrapeCity Barcode 支持的所有条形码格式?
IronBarcode 支持超过 30 种条码符号体系,包括 QR 码、Code 128、Code 39、DataMatrix、PDF417、Aztec、EAN-13、UPC-A、GS1 等等。格式自动检测功能意味着无需显式枚举格式。
IronBarcode是否支持原生PDF条码读取?
是的。IronBarcode 可以直接从 PDF 文件中读取条形码,使用 `BarcodeReader.Read("document.pdf")` 方法,无需单独的 PDF 渲染库。每页的读取结果包括页码、条形码格式、数值和置信度评分。
IronBarcode 与 GrapeCity Barcode 相比,在批量处理方面有何不同?
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 安装程序或运行时文件。
与 GrapeCity 不同,我可以在购买前评估 IronBarcode 吗?
是的。IronBarcode 的试用模式会返回完整的解码条形码值——只有生成的输出图像才会带有水印。您可以在购买前,用自己的文档测试读取准确率。
GrapeCity Barcode 和 IronBarcode 的价格有什么区别?
IronBarcode 的永久单开发者许可证起价为 749 美元,涵盖开发和生产环境。定价详情和批量许可选项请访问 IronBarcode 许可页面。无需单独的运行时许可证。
从 GrapeCity Barcode 迁移到 IronBarcode 是否很简单?
从 GrapeCity Barcode 迁移到 IronBarcode 主要涉及将基于实例的 API 调用替换为 IronBarcode 的静态方法、移除许可相关的样板代码以及更新结果属性名称。大多数迁移工作都是减少代码,而不是增加代码。
IronBarcode 能生成带有 logo 的二维码吗?
是的。`QRCodeWriter.CreateQrCode().AddBrandLogo("logo.png")` 可以将品牌图片原生嵌入二维码中,并支持配置纠错功能。此外,它还支持通过 `ChangeBarCodeColor()` 函数创建彩色二维码。

