A Comparison Between IronBarcode & QrCoder C#
在本教程中,我们将比较两个广泛使用的 C# 库——IronBarcode 和 QrCoder——它们用于处理二维码和条形码。
让我们先简要介绍一下这两个库:
IronBarcode
IronBarcode 是由 Iron Software 创建和维护的库,它使 C# 软件工程师能够在 .NET 应用程序和网站中读取和写入条形码和二维码。 它已在 NuGet 上发布,适用于所有 .NET Framework 和 .NET Core Framework。 IronBarcode 只需要一行代码即可读取或写入条形码。
二维码
QRCoder 是一个简单的 C# 库,可用于创建二维码。 它不依赖于其他库,并且在 NuGet 上提供 .NET Framework 和 .NET Core PCL 版本。
这两个库都应该具备以下主要功能:
扫描二维码 扫描条形码
- 生成二维码
- 生成条形码
我们将实现这两个库中的所有功能,并比较它们的性能。
首先,让我们在 Visual Studio 项目中安装这两个库。 由于这两个库都有自己的 NuGet 包,我们将通过 NuGet 包管理器控制台安装它们。
安装IronBarcode
要安装 IronBarcode,请在软件包管理器控制台中键入以下命令:
Install-Package BarCode
这将在我们的项目中安装 IronBarcode 库。

安装 IronBarcode
安装二维码
在软件包管理器控制台中输入以下命令:
Install-Package QRCoder
这将在我们的项目中安装 QrCoder 库。

安装二维码器
现在,我们将使用这两个库生成我们的第一个二维码。
使用 IronBarcode 生成二维码
以下代码将生成二维码。
using System;
using System.Diagnostics;
using IronBarCode;
class Program
{
static void Main()
{
// Create a stopwatch to measure the execution time
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Generate a QR code
var qrCode = QRCodeWriter.CreateQrCode("Iron Barcode Vs QrCoder");
// Save the generated QR code as a PNG file
qrCode.SaveAsPng(@"D:\Barcode Images\QrCodeByIronBarcode.png");
// Stop the stopwatch and output the execution time
stopwatch.Stop();
Console.WriteLine($"Execution Time: {stopwatch.ElapsedMilliseconds} ms");
}
}using System;
using System.Diagnostics;
using IronBarCode;
class Program
{
static void Main()
{
// Create a stopwatch to measure the execution time
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// Generate a QR code
var qrCode = QRCodeWriter.CreateQrCode("Iron Barcode Vs QrCoder");
// Save the generated QR code as a PNG file
qrCode.SaveAsPng(@"D:\Barcode Images\QrCodeByIronBarcode.png");
// Stop the stopwatch and output the execution time
stopwatch.Stop();
Console.WriteLine($"Execution Time: {stopwatch.ElapsedMilliseconds} ms");
}
}Imports System
Imports System.Diagnostics
Imports IronBarCode
Friend Class Program
Shared Sub Main()
' Create a stopwatch to measure the execution time
Dim stopwatch As New Stopwatch()
stopwatch.Start()
' Generate a QR code
Dim qrCode = QRCodeWriter.CreateQrCode("Iron Barcode Vs QrCoder")
' Save the generated QR code as a PNG file
qrCode.SaveAsPng("D:\Barcode Images\QrCodeByIronBarcode.png")
' Stop the stopwatch and output the execution time
stopwatch.Stop()
Console.WriteLine($"Execution Time: {stopwatch.ElapsedMilliseconds} ms")
End Sub
End Class创建Stopwatch实例是为了测量程序的执行时间,从而分析库的效率。

由 IronBarcode 生成的条形码
IronBarcode 的执行时间
IronBarcode 生成并保存二维码需要 3503 毫秒。

IronBarcode生成新条形码的执行时间
使用 QRCoder 创建二维码
以下示例代码将使用 QrCoder 生成二维码。
using System;
using System.Drawing;
using QRCoder;
class Program
{
static void Main()
{
// Initialize the QRCodeGenerator
QRCodeGenerator qrGenerator = new QRCodeGenerator();
// Generate QRCodeData with specified error correction level
QRCodeData qrCodeData = qrGenerator.CreateQrCode("Iron Barcode Vs QrCoder", QRCodeGenerator.ECCLevel.Q);
// Create QRCode object
QRCode qrCode = new QRCode(qrCodeData);
// Convert QRCode to Bitmap
Bitmap qrCodeImage = qrCode.GetGraphic(20);
// Save the QR code as a PNG file
qrCodeImage.Save(@"D:\Barcode Images\QrCodeByQrCoder.png");
}
}using System;
using System.Drawing;
using QRCoder;
class Program
{
static void Main()
{
// Initialize the QRCodeGenerator
QRCodeGenerator qrGenerator = new QRCodeGenerator();
// Generate QRCodeData with specified error correction level
QRCodeData qrCodeData = qrGenerator.CreateQrCode("Iron Barcode Vs QrCoder", QRCodeGenerator.ECCLevel.Q);
// Create QRCode object
QRCode qrCode = new QRCode(qrCodeData);
// Convert QRCode to Bitmap
Bitmap qrCodeImage = qrCode.GetGraphic(20);
// Save the QR code as a PNG file
qrCodeImage.Save(@"D:\Barcode Images\QrCodeByQrCoder.png");
}
}Imports System
Imports System.Drawing
Imports QRCoder
Friend Class Program
Shared Sub Main()
' Initialize the QRCodeGenerator
Dim qrGenerator As New QRCodeGenerator()
' Generate QRCodeData with specified error correction level
Dim qrCodeData As QRCodeData = qrGenerator.CreateQrCode("Iron Barcode Vs QrCoder", QRCodeGenerator.ECCLevel.Q)
' Create QRCode object
Dim qrCode As New QRCode(qrCodeData)
' Convert QRCode to Bitmap
Dim qrCodeImage As Bitmap = qrCode.GetGraphic(20)
' Save the QR code as a PNG file
qrCodeImage.Save("D:\Barcode Images\QrCodeByQrCoder.png")
End Sub
End ClassQrCoder 没有提供将二维码保存为图像的内置功能。 但是,我们可以通过将 QrCoder 解析为 Bitmap 对象来保存它。 然后我们可以使用 Bitmap 提供的保存功能保存二维码。

QrCoder 生成的条形码
二维码的执行时间
QrCoder 生成并保存二维码需要 592 毫秒。

QrCoder 生成新条形码所需的时间
分析
IronBarcode 的执行时间为 3503 毫秒,而 QrCoder 仅需 592 毫秒。 这使得 QrCoder 在性能方面比 IronBarcode 更快。
在 IronBarcode 中生成二维码要简单得多,因为我们只需要编写两行代码。 使用 QrCoder 库,只需五行代码。
IronBarcode 还提供了一个内置功能,可以将生成的二维码保存到文件中,而 QrCoder 则没有。 我们需要创建一个位图对象,以便将二维码保存到文件中。这需要我们创建四个对象,才能使用 QrCoder 生成二维码。 我们只需要在 IronBarcode 中创建一个对象就能实现同样的功能。
接下来,我们将使用这两个库生成条形码。
使用 IronBarcode 生成条形码
以下代码将使用 IronBarcode 生成条形码:
using IronBarCode;
class Program
{
static void Main()
{
// Generate a barcode with Code128 encoding
var barcode = BarcodeWriter.CreateBarcode("Iron Barcode Vs QrCoder", BarcodeEncoding.Code128);
// Save the generated barcode as a PNG file
barcode.SaveAsPng(@"D:\Barcode Images\BarcodeByIronBarcode.png");
}
}using IronBarCode;
class Program
{
static void Main()
{
// Generate a barcode with Code128 encoding
var barcode = BarcodeWriter.CreateBarcode("Iron Barcode Vs QrCoder", BarcodeEncoding.Code128);
// Save the generated barcode as a PNG file
barcode.SaveAsPng(@"D:\Barcode Images\BarcodeByIronBarcode.png");
}
}Imports IronBarCode
Friend Class Program
Shared Sub Main()
' Generate a barcode with Code128 encoding
Dim barcode = BarcodeWriter.CreateBarcode("Iron Barcode Vs QrCoder", BarcodeEncoding.Code128)
' Save the generated barcode as a PNG file
barcode.SaveAsPng("D:\Barcode Images\BarcodeByIronBarcode.png")
End Sub
End Class
使用 IronBarcode 生成条形码
使用 IronBarcode 生成条形码所需的执行时间如下:

IronBarcode的条形码生成时间
生成一个条形码需要 3756 毫秒或 3.76 秒。
使用二维码生成条形码
值得注意的是,QrCoder 库不提供创建条形码的功能。 因此,如果您需要创建条形码,IronBarcode 是更好的选择。
关于二维码扫描,我们来看看哪个库是最佳选择。
使用 IronBarcode 读取二维码
以下代码将使用 IronBarcode 读取二维码。
using System;
using IronBarCode;
class Program
{
static void Main()
{
// Read QR code from an image file
BarcodeResults results = BarcodeReader.Read(@"D:\Barcode Images\QrcodeByIronBarcode.png");
// Check if any QR codes are found
if (results != null)
{
// Loop through each result and print extracted text
foreach (BarcodeResult result in results)
{
Console.WriteLine("Extracted text from QR Code is: " + result.Text);
}
}
}
}using System;
using IronBarCode;
class Program
{
static void Main()
{
// Read QR code from an image file
BarcodeResults results = BarcodeReader.Read(@"D:\Barcode Images\QrcodeByIronBarcode.png");
// Check if any QR codes are found
if (results != null)
{
// Loop through each result and print extracted text
foreach (BarcodeResult result in results)
{
Console.WriteLine("Extracted text from QR Code is: " + result.Text);
}
}
}
}Imports System
Imports IronBarCode
Friend Class Program
Shared Sub Main()
' Read QR code from an image file
Dim results As BarcodeResults = BarcodeReader.Read("D:\Barcode Images\QrcodeByIronBarcode.png")
' Check if any QR codes are found
If results IsNot Nothing Then
' Loop through each result and print extracted text
For Each result As BarcodeResult In results
Console.WriteLine("Extracted text from QR Code is: " & result.Text)
Next result
End If
End Sub
End ClassIronBarcode 读取二维码后会返回一个Enumerable 。 我们需要遍历Enumerable来检索每个结果。 此功能有利于从文档或包含多个二维码的图像中读取二维码。

IronBarcode读取/扫描文档中所有二维码所需的时间
使用 IronBarcode 需要 3136 毫秒或 3.1 秒。
使用 QrCoder 读取二维码
QrCoder 库不提供读取或扫描二维码的功能。
使用 IronBarcode 读取条形码
以下代码将使用 IronBarcode 扫描条形码。
using System;
using IronBarCode;
class Program
{
static void Main()
{
// Read barcode from an image file
BarcodeResults results = BarcodeReader.Read(@"D:\Barcode Images\BarcodeByIronBarcode.png");
// Check if any barcodes are found
if (results != null)
{
// Loop through each result and print extracted text
foreach (BarcodeResult result in results)
{
Console.WriteLine("Text Extracted from Barcode is: " + result.Text);
}
}
}
}using System;
using IronBarCode;
class Program
{
static void Main()
{
// Read barcode from an image file
BarcodeResults results = BarcodeReader.Read(@"D:\Barcode Images\BarcodeByIronBarcode.png");
// Check if any barcodes are found
if (results != null)
{
// Loop through each result and print extracted text
foreach (BarcodeResult result in results)
{
Console.WriteLine("Text Extracted from Barcode is: " + result.Text);
}
}
}
}Imports System
Imports IronBarCode
Friend Class Program
Shared Sub Main()
' Read barcode from an image file
Dim results As BarcodeResults = BarcodeReader.Read("D:\Barcode Images\BarcodeByIronBarcode.png")
' Check if any barcodes are found
If results IsNot Nothing Then
' Loop through each result and print extracted text
For Each result As BarcodeResult In results
Console.WriteLine("Text Extracted from Barcode is: " & result.Text)
Next result
End If
End Sub
End ClassIronBarcode 读取条形码后返回Enumerable 。 我们需要循环遍历它以获取每个结果。 它有利于读取包含多个条形码的文档或图像中的条形码。
上述代码生成的输出如下:

IronBarcode扫描PDF或图像中包含的条形码所需的时间
使用二维码读取条形码
QrCoder库不提供读取或扫描二维码的功能。
现在,我们来讨论一下这两个库的许可选项。
许可
IronBarcode 的许可
IronBarcode 可供开发免费使用。 但是,要在 Visual Studio 开发环境之外部署,则需要许可证。 许可证价格范围从 $liteLicense 到 $unlimitedLicense(美元)。 购买全套铁人套装可享受折扣。

Check out IronBarcode's [licensing page](/csharp/barcode/licensing/) for more information about available licenses.
二维码 的许可
QrCoder是开源软件,因此不需要任何许可。 您可以在任何类型的环境下自由使用它。 如果你喜欢开源开发,也可以为它的源代码做贡献。
何时使用二维码
如果我们只需要生成二维码的功能,QRCoder 是最佳选择,因为它免费使用,不需要任何付款或订阅费用。
何时使用 IronBarcode
IronBarcode 在我们需要生成二维码以外的其他功能时是一个很好的选择,例如:
- 从图像或PDF中读取单个或多个条码和二维码。
- 图像校正以解决倾斜、方向、噪声、低分辨率、对比度等。
- 创建条形码并将其应用于图像或 PDF 文档。
- 将条形码嵌入到HTML文档中。
- 条形码样式设置和添加注释文本。
- 可编写二维码,并可添加徽标、颜色和高级二维码对齐功能。
摘要
下表对 IronBarcode 和 QrCoder 进行了比较。

IronBarcode 和 QrCoder 的并排比较
结论
IronBarcode for .NET 允许开发人员使用一行代码在其 .NET 应用程序中读取和写入条形码和二维码。 该库支持大多数条形码和二维码标准,包括 39/93/128、UPC A/E、EAN 8/13 和 QR 等。 该库可自动预处理条形码图像,并提供旋转、噪声、失真和倾斜校正,以提高速度和准确性。 IronBarcode 与 32 位和 64 位系统、所有 .NET 语言以及各种平台兼容,包括桌面、控制台、云、移动和 Web 应用程序。 它还允许开发人员为 PDF、JPG、TIFF、GIF、BMP、PNG 和 HTML 文档编写条形码和二维码,并修改文本颜色、大小、旋转和质量。 该图书馆安全可靠,不使用网络服务,也不通过互联网发送数据。 IronBarcode 提供免费试用版,并提供三种许可选项,包括供个人使用的 Lite 版本、供最多 10 名开发人员团队使用的专业版套餐以及供公司使用的无限版套餐。
QRCoder 是一个 C# .NET 库,它根据 ISO/IEC 18004 生成二维码,不依赖于其他库。 它提供多种二维码渲染类,包括 QRCode、ArtQRCode、AsciiQRCode 等。 但是,并非所有渲染器都适用于所有目标框架,.NET Standard/.NET >=5.0 版本有一些限制。 QRCoder是免费的,无需许可证。
IronBarcode 比 QrCoder 功能更全面,因为它支持所有 .NET Framework 版本,具有更广泛的功能,并提供 SaaS 和 OEM 再分发服务。 IronBarcode 还提供全面的文档和 24/7 全天候支持,而 QRCoder 则不提供。 IronBarcode 会收取许可费,但考虑到它提供的功能和支持,这个费用是合理的。
IronBarcode 是由Iron Software开发的库,该公司还提供其他有用的库,包括IronPDF 、 IronXL 、 IronOCR和IronWebScraper 。 购买全套Iron Suite产品,即可享受超值折扣,获得全部五款产品。
总而言之,IronBarcode 最适合那些需要同时处理条形码和二维码,并希望创建条形码生成器、二维码生成器、条形码阅读器和二维码阅读器的人。 另一方面,QRCoder 适合那些只需要创建二维码生成器的人。
常见问题解答
如何在 C# 中生成 QR 码?
要在 C# 中生成 QR 码,你可以使用 QrCoder 库,这是一个简单且开源的库。另外,你可以使用 IronBarcode 来获得更高级的功能,如样式化 QR 码并将其集成到文档中。
使用 IronBarcode 相对于 QrCoder 有什么优势?
IronBarcode 提供广泛的功能,如读取条形码和 QR 码、图像校正以及将条形码嵌入到 PDF 和其他文档中。它非常适合需要全面条形码和 QR 码操作的项目。
有没有免费的库可以在 C# 中生成 QR 码?
是的,QrCoder 是一个用于生成 QR 码的免费开源库。它不需要许可,使其成为简单 QR 码生成的高性价比选项。
我可以用 QrCoder 读取 QR 码吗?
不,QrCoder 不支持读取或扫描 QR 码。要读取 QR 码,你可以使用 IronBarcode,它提供此功能以及其他附加功能。
如何在 .NET 项目中安装 QR 码库?
你可以使用 NuGet 包管理器控制台,用命令 Install-Package QRCoder 安装 QrCoder。对于 IronBarcode,使用 Install-Package IronBarcode。
IronBarcode 和 QrCoder 之间的 QR 码生成执行时间有什么区别?
QrCoder 更快,大约需要 592 毫秒来生成和保存一个 QR 码,而 IronBarcode 大约需要 3503 毫秒。但是,IronBarcode 提供了比单纯 QR 码生成更高级的功能。
IronBarcode 部署是否需要许可证?
是的,IronBarcode 部署在 Visual Studio 开发环境之外需要许可证。它提供不同的许可选项,包括 Lite、Professional 和 Unlimited 套餐。
IronBarcode 提供了哪些条形码处理的功能?
IronBarcode 允许读取和写入条形码和 QR 码、图像校正、样式化选项,以及将条形码嵌入到例如 PDF 等文档中,使其成为条形码处理的综合工具。
对于简单的 QR 码生成,我应该选择哪个库?
对于简单的 QR 码生成,QrCoder 是一个合适的选择,因为它易于使用且有免费许可。然而,对于更高级的任务,推荐使用 IronBarcode。
我可以使用 C# 将 QR 码集成到 PDF 中吗?
是的,你可以使用 IronBarcode 将 QR 码集成到 PDF 中。它提供功能读取和写入 QR 码和条形码,并无缝地将其嵌入到文档中。







