跳至頁尾內容
與其他組件的比較

ZXing解碼器與IronBarcode的比較

線條碼提供了一種清晰且機器可讀的方法來呈現資料。 最初,條碼由不同寬度和間距的平行線組成,作為資料的表現。 這些傳統的線性或一維(1D)條碼可以由專業的光學裝置──稱為條碼閱讀器──掃描。 然而,條碼的發展導致了二維(2D)條碼的發明,也稱為矩陣碼的出現。 與傳統條碼不同,2D條碼利用矩形、點和六邊形等圖案,而不是條。 為了讀取這些2D條碼,可以使用特定的光學掃描設置,或者使用連接到運行解碼軟體之電腦的數位相機。 此外,像智慧型手機這樣的行動裝置可以利用其內建相機和專用應用程式作為2D條碼掃描器。

ZXing 條碼掃描器

人行斑馬線,通常稱為ZXing,是一種開源、多格式的1D/2D條碼圖像處理工具包,是用Java開發的,並有其他語言的移植。 ZXing由核心圖像解碼庫、Java專用客戶端程式碼和Android客戶端條碼掃描器等模組組成。 許多獨立的開源專案是基於它之上的。

1. 功能特色

  • 它可以跟蹤URL,聯繫人資訊,日曆事件等。
  • 它是針對Java SE應用程式建立的。
  • 條碼掃描器的整合是可能的。
  • 這是個簡單的Google Glass應用程式。

2. 在.NET中使用ZXing

開啟Visual Studio,從檔案選單中選擇"新專案",然後選擇"控制台應用程式"。 在本文中,我們選擇C#控制台應用。

 C#開發者如何在ZXing中掃描條碼 圖1

在適當的文字框中輸入專案名稱和檔案路徑。 接下來,點選"建立"按鈕來選擇所需的.NET Framework。

如果您選擇了控制台應用程式,該專案現在將建立其結構並開啟program.cs檔案,允許您鍵入程式碼並建造或執行它。

 C#開發者如何在ZXing中掃描條碼 圖2

2.1 安裝ZXing條碼

在NuGet套件管理器控制台中輸入以下命令以安裝ZXing程式庫:

Install-Package ZXing.Net.Bindings.Windows.Compatibility

或者,您可以使用NuGet套件管理器工具獲取該套件。 像下面的說明一樣。 嘗試安裝您選擇的第一個結果。

 C#開發者如何在ZXing中掃描條碼 圖3

2.2 使用ZXing讀寫條碼

我們可以使用以下範例程式碼來建立條碼。 ZXing允許我們建立超過10種條碼格式。

using ZXing.Windows.Compatibility;

var options = new QrCodeEncodingOptions
{
    Width = 250,
    Height = 250,
};

var writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;

// Encode the string into a QR code bitmap image
System.Drawing.Bitmap _bitmap = writer.Write("Hello world");

// Save the bitmap as a PNG file
_bitmap.Save("Demo1.png");
using ZXing.Windows.Compatibility;

var options = new QrCodeEncodingOptions
{
    Width = 250,
    Height = 250,
};

var writer = new BarcodeWriter();
writer.Format = BarcodeFormat.QR_CODE;
writer.Options = options;

// Encode the string into a QR code bitmap image
System.Drawing.Bitmap _bitmap = writer.Write("Hello world");

// Save the bitmap as a PNG file
_bitmap.Save("Demo1.png");
Imports ZXing.Windows.Compatibility

Private options = New QrCodeEncodingOptions With {
	.Width = 250,
	.Height = 250
}

Private writer = New BarcodeWriter()
writer.Format = BarcodeFormat.QR_CODE
writer.Options = options

' Encode the string into a QR code bitmap image
Dim _bitmap As System.Drawing.Bitmap = writer.Write("Hello world")

' Save the bitmap as a PNG file
_bitmap.Save("Demo1.png")
$vbLabelText   $csharpLabel

上面的程式碼設置了QrCodeEncodingOptions的高度和寬度。 然後它建立了一個BarcodeWriter的實例。 對於BarcodeWriter,我們將條碼格式設置為QR碼。 我們將先前建立的QR碼選項指派給作家。 BarcodeWriter中將給定的字串編碼成條碼,並將其返回為位圖圖像。 該圖像使用位圖的Save方法保存。以下是程式碼的結果。

 C#開發者如何在ZXing中掃描條碼 圖4

下一個程式碼範例展示了如何使用ZXing解碼條碼。

using ZXing.Windows.Compatibility;

// Load the barcode image into a bitmap
var barcodeBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("demo.png");

// Create a BarcodeReader object
var reader = new BarcodeReader();

// Decode the bitmap into a result
var result = reader.Decode(barcodeBitmap);

if (result != null)
{
    // Output the decoded text to the console
    Console.WriteLine(result.Text);
    Console.ReadKey();
}
using ZXing.Windows.Compatibility;

// Load the barcode image into a bitmap
var barcodeBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("demo.png");

// Create a BarcodeReader object
var reader = new BarcodeReader();

// Decode the bitmap into a result
var result = reader.Decode(barcodeBitmap);

if (result != null)
{
    // Output the decoded text to the console
    Console.WriteLine(result.Text);
    Console.ReadKey();
}
Imports ZXing.Windows.Compatibility

' Load the barcode image into a bitmap
Private barcodeBitmap = CType(System.Drawing.Bitmap.FromFile("demo.png"), System.Drawing.Bitmap)

' Create a BarcodeReader object
Private reader = New BarcodeReader()

' Decode the bitmap into a result
Private result = reader.Decode(barcodeBitmap)

If result IsNot Nothing Then
	' Output the decoded text to the console
	Console.WriteLine(result.Text)
	Console.ReadKey()
End If
$vbLabelText   $csharpLabel

在上面的程式碼中,我們首先將圖像載入到位圖中,然後建立一個BarcodeReader物件。 Decode函式允許我們將位圖作為參數傳遞,這可以以多種格式返回結果。 我們使用Text屬性來獲取條碼中編碼的文字。

 C#開發者如何在ZXing中掃描條碼 圖5

IronBarcode

借助這個條碼程式庫,讀取和建立條碼非常簡單。 借助IronBarcode的Library,動態條碼易於製作。 只需幾行程式碼,這個簡單的程式庫就能生成條碼,幫助我們編碼條碼圖像。 IronBarcode允許我們用C#和VB.NET生成條碼。

1. 功能特色

  • IronBarcode可以讀寫大多數條碼圖像格式和QR標準,包括UPCA/E、Databar、EAN8/13、MSI、Code39/93/128、CodaB、RSS14/Expanded和ITF。
  • 在掃描掃描和實時影片幀時,IronBarcode可以校正旋轉、噪音、失真和傾斜。 為了提高讀取精度和速度,IronBarcode在建立過程中會自動預處理條碼圖像。 因為允許更改內容,所以動態條碼經常被使用。
  • IronBarcode利用多核和執行緒的能力對批處理伺服器有利。
  • 在單頁和多頁文件中,IronBarcode可以自動找到一個或多個條碼。

2. 使用IronBarcode

要在解決方案中利用IronBarcode程式庫,您必須下載所需的套件。 為此,請在NuGet套件管理器控制台中使用以下命令:

Install-Package BarCode

作為替代方案,您可以使用NuGet套件管理器來查找及下載"條碼"套件,這會顯示所有搜尋結果。 然後您可以從中選擇所需的套件下載到程式中。

 C#開發者如何在ZXing中掃描條碼 圖6

3. 使用IronBarcode讀寫條碼

只需幾行程式碼,我們就可以快速使用IronBarcode程式庫製作條碼圖像。 此外,它可讓我們將建立的條碼另存為獨立圖片文件。這是一些使用Console程式建立條碼標籤的C#範例程式碼。

using IronBarCode;

// Create a QR code with a medium error correction level
QRCodeWriter.CreateQrCode("Your text here", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("demo.png");
using IronBarCode;

// Create a QR code with a medium error correction level
QRCodeWriter.CreateQrCode("Your text here", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("demo.png");
Imports IronBarCode

' Create a QR code with a medium error correction level
QRCodeWriter.CreateQrCode("Your text here", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("demo.png")
$vbLabelText   $csharpLabel

此程式碼使用中等級別的錯誤修正生成500 x 500像素的圖像,然後使用SaveAsPng方法將其保存到文件位置。

下一個程式碼範例讀取我們在上一個範例中建立的QR碼中編碼的文字。

using IronBarCode;

// Load the QR code image into a bitmap
var barcodeBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("demo.png");

// Read the barcode image
var reader = IronBarCode.BarcodeReader.Read(barcodeBitmap);

// Output the decoded value to the console
Console.WriteLine(reader.Values[0]);
Console.ReadKey();
using IronBarCode;

// Load the QR code image into a bitmap
var barcodeBitmap = (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile("demo.png");

// Read the barcode image
var reader = IronBarCode.BarcodeReader.Read(barcodeBitmap);

// Output the decoded value to the console
Console.WriteLine(reader.Values[0]);
Console.ReadKey();
Imports IronBarCode

' Load the QR code image into a bitmap
Private barcodeBitmap = CType(System.Drawing.Bitmap.FromFile("demo.png"), System.Drawing.Bitmap)

' Read the barcode image
Private reader = IronBarCode.BarcodeReader.Read(barcodeBitmap)

' Output the decoded value to the console
Console.WriteLine(reader.Values(0))
Console.ReadKey()
$vbLabelText   $csharpLabel

我們首先將圖像載入到位圖中,然後使用BarcodeReader類上讀取圖像。 我們在從Values屬性來獲取從QR碼中讀取的內容。

要了解有關ZXing的更多資訊及其與IronBarcode的比較,請閱讀這篇下一篇部落格文章

我們的讀取條碼教程還提供了有關如何使用IronBarcode讀取條碼和QR碼的更多資訊。 更多有關IronBarcode的程式碼教程。

結論

ZXing條碼掃描器可以建立高品質的條碼,但它已經過時,僅支援少數條碼格式。 它的文件和產品支援也有限。

另一方面,IronBarcode效率高且靈活,可以在很多操作系統上運行。 IronBarcode可以更改條碼中使用的顏色、大小、間距和字母。 它還支援Crystal Reports。

開發者可以免費使用IronBarcode。 使用者可以購買授權來獲得額外功能的存取權限及全年的支援和產品更新。

ZXing是其各自所有者的註冊商標。 本網站不隸屬於、未經ZXing認可或贊助。 所有產品名稱、標誌和品牌均為其各自所有者的財產。 比較僅供資訊參考,並反映了撰寫時公開可用的資訊。)}]

常見問題

如何在C#中將HTML轉換為PDF?

您可以使用IronPDF的RenderHtmlAsPdf方法將HTML字串轉換成PDF。您也可以使用RenderHtmlFileAsPdf將HTML檔案轉換成PDF。

IronBarcode和ZXing之間有什麼不同?

IronBarcode提供更大的靈活性,並相較於ZXing支援更廣泛的條碼格式。儘管ZXing在建立條碼方面效果不錯,但在格式支援及文件方面有限。IronBarcode在效率上表現出色,並與各種作業系統相容。

如何使用行動裝置掃描條碼?

使用ZXing安卓客戶端條碼掃描器,您可以利用裝置的相機掃描條碼。為了獲得更多的功能,IronBarcode可以整合至行動應用程式中以增強條碼掃描能力。

IronBarcode是否支援2D條碼?

是的,IronBarcode支援1D和2D條碼,包括QR碼,允許多樣化的條碼讀取與建立。

IronBarcode能否處理動態條碼的建立?

IronBarcode支援動態條碼建立,允許您根據特定需求自訂條碼的顏色、大小、間距和文字。

整合IronBarcode到.NET專案中需要什麼?

要將IronBarcode整合到.NET專案中,請通過NuGet Package Manager Console使用Install-Package IronBarcode安裝該套件,或者在NuGet Package Manager中找到它。

使用IronBarcode有費用嗎?

IronBarcode提供免費試用,但購買授權可獲得額外功能、產品更新和一年的支援。

IronBarcode可以用來從影片幀中讀取條碼嗎?

是的,IronBarcode可以處理實時影片幀,校正旋轉、噪音、失真和偏斜,以提高條碼掃描的準確性和速度。

ZXing的條碼掃描功能有哪些?

ZXing提供了一個開放源碼的條碼掃描工具包,特別是針對1D和2D條碼。它包括核心影像解碼程式庫和Android的客戶端條碼掃描器。

IronBarcode支持哪些程式語言?

IronBarcode支持C#和VB.NET,非常適合在.NET框架內工作的開發人員。

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話