跳過到頁腳內容
與其他組件的比較

IronBarcode與QrCoder C#的比較

在本教程中,我們將比較兩個廣泛使用的 C# 庫——IronBarcode 和 QrCoder——用於處理 QR 碼和條碼。

讓我們從對這兩個庫的簡要介紹開始:

IronBarcode

IronBarcode 是 Iron Software 創建和維護的一個庫,使 C# 軟體工程師能夠在 .NET 應用程式和網站中讀寫條碼和 QR 碼。 它可在 NuGet 上獲得,適用於所有 .NET 框架和 .NET Core 框架。 IronBarcode 只需一行代碼即可讀寫條碼。

QrCoder

QRCoder 是一個簡單的 C# 庫,允許您創建 QR 碼。 它不依賴於其他庫,並可在 NuGet 上獲得 .NET Framework 和 .NET Core PCL 版本。

兩個庫都應該有以下主要功能:

  • 掃描 QR 碼
  • 掃描條碼
  • 生成 QR 碼
  • 生成條碼

我們將從這兩個庫中實現所有這些功能並比較它們的性能。

首先,讓我們在我們的 Visual Studio 專案中安裝這兩個庫。 由於這兩個庫都有自己的 NuGet 包,我們將通過 NuGet 包管理器控制台安裝它們。

安裝 IronBarcode

要安裝 IronBarcode,請在包管理器控制台中輸入以下命令:

Install-Package BarCode

這將在我們的專案中安裝 IronBarcode 庫。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 1: Installing IronBarcode

class="content__image-caption">安裝 IronBarcode

安裝 QrCoder

在包管理器控制台中輸入以下命令:

Install-Package QRCoder

這將在我們的專案中安裝 QrCoder 庫。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 2: Installing QrCoder

class="content__image-caption">安裝 QrCoder

現在,我們將使用這兩個庫生成我們的第一個 QR 碼。

使用 IronBarcode 生成 QR 碼

以下代碼將生成一個 QR 碼。

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
$vbLabelText   $csharpLabel

Stopwatch 實例用於測量程式的執行時間,以分析庫的效率。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 3: IronBarcode Result

class="content__image-caption">由 IronBarcode 生成的條碼

IronBarcode 的執行時間

IronBarcode 需要 3503 毫秒來生成並保存一個 QR 碼。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 4: Execution Time

class="content__image-caption">IronBarcode 生成新條碼的執行時間

使用 QRCoder 創建 QR 碼

以下示例代碼將使用 QrCoder 生成一個 QR 碼。

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 Class
$vbLabelText   $csharpLabel

QrCoder 不提供將 QR 碼保存為圖像的內建功能。 但我們可以通過將 QrCoder 解析為 Bitmap 對象來保存。 然後,我們可以使用 Bitmap 提供的保存功能來保存 QR 碼。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 5: QR Coder Result

class="content__image-caption">QrCoder 生成的條碼

Qrcoder 的執行時間

QrCoder 需要 592 毫秒來生成並保存一個 QR 碼。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 6: QrCoder's Execution Time

class="content__image-caption">QrCoder 生成新條碼所耗時間

分析

IronBarcode 的執行時間為 3503 毫秒,而 QrCoder 僅需 592 毫秒。 這使得 QrCoder 在性能方面比 IronBarcode 更快。

在 IronBarcode 中生成 QR 碼要簡單得多,因為我們只需寫兩行代碼。 使用 QrCoder 庫則需要五行代碼。

IronBarcode 還提供了一個內建功能,將生成的 QR 碼保存到文件中,而 QrCoder 則沒有。 我們必須創建一個位圖對象,以將 QR 碼保存到文件中。這需要我們創建四個對象來使用 QrCoder 生成 QR 碼。 要完成同樣的事情,在 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
$vbLabelText   $csharpLabel
class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 7: Generated barcode using IronBarcode

class="content__image-caption">使用 IronBarcode 生成的條碼

下面是使用 IronBarcode 生成條碼所需的執行時間:

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 8: Execution time for IronBarcode to generate a new Barcode

class="content__image-caption">IronBarcode 的條碼生成時間

生成條碼需要 3756 毫秒或 3.76 秒。

使用 QrCoder 生成條碼

值得注意的是,QrCoder 庫不提供創建條碼的功能。 所以,如果需要創建條碼,IronBarcode 是更好的選擇。

至於 QR 碼掃描,讓我們看看哪個庫是更好的選擇。

使用 IronBarcode 讀取 QR 碼

以下代碼將使用 IronBarcode 讀取 QR 碼。

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 Class
$vbLabelText   $csharpLabel

IronBarcode 會以 Enumerable 的形式返回讀取 QR 碼的結果。 我們需要遍歷 Enumerable 來檢索每個結果。 這個功能對於從文件或包含多個 QR 碼的圖像中讀取 QR 碼很有用。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 9: IronBarcode's QR Code Scanning Execution Time

class="content__image-caption">IronBarcode 讀取/掃描文件中所有 QR 碼所需的時間

使用 IronBarcode 需要 3136 毫秒或 3.1 秒。

使用 QrCoder 讀取 QR 碼

QrCoder 庫不提供讀取或掃描 QR 碼的功能。

使用 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 Class
$vbLabelText   $csharpLabel

IronBarcode 會以 Enumerable 的形式返回讀取條碼的結果。 我們需要進行遍歷以獲取每個結果。 這對於從文件或包含多個條碼的圖像中讀取條碼很有用。

上面代碼生成的輸出如下:

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 10: Execution time for IronBarcode Scan one or more barcodes

class="content__image-caption">IronBarcode 掃描 PDF 或圖像中條碼所需的時間

使用 QrCoder 讀取條碼

QrCoder 庫不提供讀取或掃描 QR 碼的功能。

現在,讓我們討論這兩個庫的許可選項。

許可

許可 for IronBarcode

IronBarcode 是開發免費的。 但在視覺工作室開發環境之外部署時需要許可。 許可價格範圍為 $liteLicense 到 $unlimitedLicense (USD)。 如果您購買完整的Iron Suite,可以享受折扣。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 11: Iron Licenses

class="content__image-caption">檢查 IronBarcode 的[許可頁面](/csharp/barcode/licensing/) 以獲取有關可用許可的更多資訊。

許可 for QrCoder

QrCoder 是開源的,因此不需要任何許可。 可以在任何類型的環境中自由使用。 如果您喜歡開源開發,也可以貢獻其源代碼。

何時使用 QrCoder

如果我們只需要生成 QR 碼的功能,QRCoder 是最佳選擇,因為它是免費的,並且不需要任何支付或訂閱費用。

何時使用 IronBarcode

當我們需要生成 QR 碼以外的更多功能時,IronBarcode 是一個很好的選擇,例如:

  • 從圖像或 PDFs 中讀取單個或多個條碼和 QR 碼。
  • 圖像校正以解決扭曲、方向、噪音、低分辨率、對比度等問題。
  • 創建條碼並將其應用到圖像或 PDF 文件中。
  • 將條碼嵌入到 HTML 文檔中。
  • 樣式條碼並添加註釋文本。
  • 案文 QR 寫入允許添加徽標、顏色和高階 QR 對齊。

總結

下表比較了 IronBarcode 和 QrCoder。

class="content-img-align-center"> A Comparison Between IronBarcode and QrCoder C# - Figure 12: Comparing the two libraries

class="content__image-caption">IronBarcode 和 QrCoder 的並排比較

結論

IronBarcode for .NET 允許開發人員在其 .NET 應用程式中僅用一行代碼就可以讀寫條碼和 QR 碼。 該庫支持大多數條碼和 QR 碼標準,包括 39/93/128, UPC A/E, EAN 8/13 和 QR 等。 該庫自動預處理條碼圖像,並提供旋轉、噪音、失真和扭曲的校正,以提高速度和準確性。 IronBarcode 與 32 位和 64 位系統兼容,支持所有 .NET 語言,以及桌面、控制台、雲、行動和 Web 應用程式等多種平台。 它還允許開發人員為 PDF、JPG、TIFF、GIF、BMP、PNG 和 HTML 文檔寫入條碼和 QR 碼,並修改文本顏色、大小、旋轉和質量。 該庫是安全的,不使用網絡服務或通過互聯網傳輸數據。 IronBarcode 提供免費試用,並提供三種許可選擇,包括個人使用的 Lite 版本,適用於多達 10 位開發者的專業包和公司的無限制包。

QRCoder 是一個 C# .NET 庫,基於 ISO/IEC 18004 生成 QR 碼,無需依賴其他庫。 它提供了多個 QR 碼呈現類,包括 QRCode,ArtQRCode,AsciiQRCode 等。 然而,並非所有呈現器在所有目標框架上都可用,而且 .NET Standard/.NET >=5.0 版本有一些限制。 QRCoder 是免費的,且不需要許可。

IronBarcode 比 QrCoder 更加多樣化,因為它支持所有 .NET Framework 版本,具有更廣泛的功能,並提供 SAAS 和 OEM 再分配的包涵。 IronBarcode 還提供全面的文件和24/7支持,而 QRCoder 沒有。 IronBarcode 有許可費用,但考慮到其提供的功能和支持,這是合理的。

IronBarcode is a library developed by Iron Software, which also offers other useful libraries, including IronPDF, IronXL, IronOCR, and IronWebScraper. 購買完整的 Iron Suite 以驚人的折扣獲得所有五個產品。

總而言之,IronBarcode 非常適合需要處理條碼和 QR 碼,並希望創建條碼生成器,QR 碼生成器,條碼閱讀器和 QR 代碼閱讀器的人使用。 另一方面,QRCoder 適合那些只需要創建 QR 碼生成器的人。

[{i:(QrCoder 是其各自所有者的註冊商標。 此站點與 QrCoder 沒有關聯、沒有被其認可也不是其提攜。 所有產品名稱、徽標和品牌均為其各自所有者的財產。 比較僅供參考,反映撰寫時公開可用的信息。

常見問題解答

如何在C#中生成QR碼?

要在C#中生成QR碼,您可以使用QrCoder庫,這是一個簡單且開源的庫。或者,您可以使用IronBarcode以獲得更高級的功能,例如樣式化QR碼並將其集成到文件中。

使用IronBarcode而非QrCoder的優勢是什麼?

IronBarcode提供了廣泛的功能,例如讀取條形碼和QR碼、影像校正以及將條形碼嵌入到PDF等文件中。它非常適合需要全面條形碼和QR碼操作的專案。

是否有免費的庫用於在C#中生成QR碼?

是的,QrCoder是一個免費且開源的庫,用於在C#中生成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等文件中,使其成為條形碼處理的全面工具。

我應該選擇哪個庫用於在C#中生成簡單的QR碼?

對於簡單的QR碼生成,QrCoder是一個合適的選擇,因為它易於使用且免費授權。然而,對於更高級的任務,建議使用IronBarcode。

我可以使用C#將QR碼集成到PDF中嗎?

是的,您可以使用IronBarcode將QR碼嵌入到PDF中。它提供了讀取和寫入QR碼和條形碼以及將其無縫嵌入到文檔中的功能。

Jordi Bardia
軟體工程師
Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担产品测测试,产品开发和研究的责任时,Jordi 为持续的产品改进增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。