IronBarcode和BarcodeLib之間的比較
條碼是一種機器可讀的資料視覺表示。 條碼最早是通過改變平行線的長度和間隔來表達資料。 這些線性或一維 (1D) 條碼可以使用專門的光學掃描儀——條碼讀取器來掃描,後來出現了使用矩形、點、六邊形和其他圖案的二維 (2D) 變體,儘管不使用條,仍被稱為矩陣碼。 專門設計的2D光學掃描儀有多種配置,可以讀取2D條碼。 連接到微型計算機的數碼相機可以拍攝條碼的照片圖像,同時運行掃描2D條碼的軟體——它通過分析圖像來解析並解碼條碼。 使用內建相機(如智能手機)的移動裝置可以作為2D條碼掃描儀的後者型別。
在本文中,我們將比較兩個受歡迎的條碼庫:
- Aspose.BarCode
- IronBarcode
兩個庫都可以用於條碼的生成和識別。 所有.NET框架都支持,並且條碼圖像可以輕鬆保存。
功能
Aspose.BarCode
Aspose.BarCode for .NET是一個複雜的工具,允許您從多種圖片來源以任何角度建立和識別1D和2D條碼。 開發人員可以輕鬆地將條碼建立和掃描功能新增到.NET應用程式中。 它還允許將生成的條碼導出到多個高品質圖片格式,以及API用於從各種角度建立新條碼和識別舊條碼。 支持超過60種不同的1D、2D和郵政條碼符號。
Aspose.BarCode for .NET允許您更改生成的條碼的背景色、條色、旋轉角度、x維度、圖像質量、解析度、標題、大小等。 API還支持多種識別和成像功能以及多種符號。
- Aspose允許我們只需幾行程式碼就可以生成和識別40多種條碼符號。
- 以任何角度讀取條碼。
- 輕鬆將條碼標籤列印到實體或虛擬列印機。
- 支持校驗和條碼補充資料。
- 改進了Code128編碼。
- 設置條碼將被掃描的圖像區域。
- 建立依賴裝置解析度的圖像。
- 識別格式和圖像:JPEG、TIFF、PNG、BMP、GIF、EXIF 保存條碼標籤為圖像:EMF、SVG 平台獨立性、2D和郵政條碼。
IronBarcode
IronBarcode for .NET允許程式設計師從.NET應用程式和網站中讀寫條碼和QR碼。 IronBarcode只需要一行程式碼來讀寫條碼。 大多數條碼和QR標準可以使用.NET條碼庫讀寫。 Code 39/93/128、UPC A/E、EAN 8/13、ITF、RSS 14/擴展、Databar、CodaBar、Aztec、Data Matrix、MaxiCode、PDF417、MSI、Plessey、USPS和QR是最常見的一些。 條碼結果資料包含型別、文字、二進制資料、頁面和圖片文件。 IronBarcode的API功能如下:
- IronBarcode讀寫大多數條碼型別和QR標準,包括UPC A/E、EAN 8/13、Code 39/93/128、ITF、MSI、RSS 14/擴展、Databar、CodaBar、QR、樣式QR、Data Matrix、MaxiCode、PDF417、Plessey和Aztec。 結果提供的條碼資料、型別、頁面、文字和條碼圖片非常適合存檔或索引系統。
- 圖像預處理提高了讀取速度和精確性——IronBarcode自動預處理條碼圖片以增加讀取速度和精確性。 它可以讀取掃描或實時影片幀,也可校正旋轉、噪聲、失真和傾斜。 批量處理伺服器應用程式可以利用多核和多執行緒。 自動在單頁和多頁文件中找到一個或多個條碼。 不需要使用複雜的API,您可以搜尋特定的條碼型別或文件位置。
- 為.NET專案設計——只需幾行程式碼即可在幾分鐘內啟動和運行。 為.NET Framework構建為單個DLL,無需依賴。 支持32和64位,並可以在任何.NET和.NET核心語言中使用。 支持Web、雲端、桌面和控制台應用程式中的移動和桌面裝置。
- 為各種文件格式建立條碼和QR碼——保存並列印到文件或以PDF、JPG、TIFF、GIF、BMP、PNG和HTML等多種文件和流格式中。 顏色、質量、旋轉、大小和文字都可以改變。
1. 建立新專案
打開Visual Studio,轉到文件選單,選擇"新專案",然後選擇控制台應用程式/Windows Forms/WPF 應用程式。 條碼也可以用於所有型別的應用程式。 您還可以使用Webform/MVC/MVC Core等應用程式。
在適當的文字框中輸入專案名稱並選擇文件路徑。 然後,按下建立按鈕並選擇所需的.NET框架。 專案將生成所選應用程式的結構,如果您選擇了控制台應用程式,則會打開program.cs文件,在那裡您可以輸入程式碼並構建/運行應用程式。
2. 安裝條碼庫
2.1 使用IronBarcode
可以通過四種方式下載並安裝IronBarcode程式庫。
這些方法是:
- 使用Visual Studio
- 使用Visual Studio命令行
- 從NuGet網站直接下載
- 從IronBarcode網站直接下載
2.1.1 使用Visual Studio
Visual Studio提供了NuGet Package管理器選項,可直接將套件安裝到方案中。 以下截圖顯示了如何打開NuGet Package Manager。
它提供了一個搜尋框,以顯示來自NuGet網站的套件列表。在套件管理器中,我們需要搜尋關鍵字"Barcode",如下圖所示:
從上面的圖片中,我們會獲得相關搜尋結果列表。 我們需要選擇所需的選項將套件安裝到方案中。
2.1.2 使用Visual Studio命令行
在Visual Studio中,轉到工具 -> NuGet Package Manager -> Package Manager Console。
在控制台選項卡中輸入以下命令:
Install-Package BarCode
套件現在將下載/安裝到當前專案中並準備使用。
2.1.3 從NuGet網站直接下載
第三種方式是直接從網站下載程式包。
- 瀏覽 NuGet連結
- 從右側選單中選擇下載套件選項。
- 雙擊下載的套件。 它將自動安裝。
- 然後,重新載入方案並在專案中開始使用。
2.1.4 從IronBarcode網站直接下載
點擊這裡 以從網站直接下載最新套件。下載完成後,按照以下步驟將套件新增到專案中。
- 右鍵單擊方案窗口中的專案。
- 接下來,選擇選項參考然後瀏覽下載的參考的目錄。
- 接下來,單擊確定以新增參考。
2.2 使用Aspose.BarCode
可以通過四種方式下載並安裝Aspose.BarCode程式庫。
這些方法是:
- 使用Visual Studio
- 使用Visual Studio命令行
- 從NuGet網站直接下載
- 從Aspose網站直接下載
2.2.1 使用Visual Studio
此方法與上面描述的IronBarcode類似。 我們只需要更改搜索條件,如下圖所示。
選擇第一個選項,將下載Aspose.BarCode程式庫。
2.2.2 使用Visual Studio命令行
在Visual Studio中,轉到工具 > NuGet Package Manager > Package Manager Console
在套件管理器控制台選項卡中輸入以下行。
Install-Package Aspose.BarCode
套件現在將下載/安裝到當前專案中並準備使用。
2.2.3 從NuGet網站直接下載
第三種方式是直接從網站下載程式包。
只需點擊這裡,它將重定向到NuGet網站,您可以在那裡下載套件。
2.2.4 從Aspose網站直接下載
點擊這裡,它將重定向到套件版本列表,我們可以選擇所需的版本下載。 下載完成後,按照以下步驟將套件新增到專案中。
- 右鍵單擊方案窗口中的專案。
- 接下來,選擇選項參考,然後瀏覽下載的參考的目錄。
- 接下來,單擊確定以新增參考。
3. 條碼生成
使用IronBarcode和Aspose.BarCode可以輕鬆生成條碼。 讓我們通過一個範例來看看這一點。
3.1 使用IronBarcode
IronBarcode可以用來建立可以保存為多種圖像格式的條碼標籤。 我們還可以傳遞需要生成的條碼型別。 下面是條碼生成的程式碼片段:
using IronBarCode;
// Create a barcode using IronBarcode
var MyBarCode = BarcodeWriter.CreateBarcode("123456", BarcodeEncoding.Code128);
// Add annotation text below the barcode
MyBarCode.AddAnnotationTextBelowBarcode("123456");
// Save the barcode as a JPEG image
MyBarCode.SaveAsImage("MyBarCode.jpeg");
using IronBarCode;
// Create a barcode using IronBarcode
var MyBarCode = BarcodeWriter.CreateBarcode("123456", BarcodeEncoding.Code128);
// Add annotation text below the barcode
MyBarCode.AddAnnotationTextBelowBarcode("123456");
// Save the barcode as a JPEG image
MyBarCode.SaveAsImage("MyBarCode.jpeg");
Imports IronBarCode
' Create a barcode using IronBarcode
Private MyBarCode = BarcodeWriter.CreateBarcode("123456", BarcodeEncoding.Code128)
' Add annotation text below the barcode
MyBarCode.AddAnnotationTextBelowBarcode("123456")
' Save the barcode as a JPEG image
MyBarCode.SaveAsImage("MyBarCode.jpeg")
BarcodeWriter.CreateBarcode 是IronBarcode程式庫中可用的方法。 我們需要為CreateBarcode函式傳遞兩個參數:要編碼的文字和要生成的條碼型別。 調用此方法後,它將返回一個條碼物件,可以用來設置各種屬性,如新增註釋文字並以不同格式保存圖像。
// Create a QR code with a logo image
var QRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("Hello World", "logo.png", 500);
// Change the color of the barcode to dark green
QRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
// Save the QR code with a logo as a JPEG image
QRWithLogo.SaveAsJpeg("Logoqr.jpeg");
// Create a QR code with a logo image
var QRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("Hello World", "logo.png", 500);
// Change the color of the barcode to dark green
QRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
// Save the QR code with a logo as a JPEG image
QRWithLogo.SaveAsJpeg("Logoqr.jpeg");
' Create a QR code with a logo image
Dim QRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("Hello World", "logo.png", 500)
' Change the color of the barcode to dark green
QRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen)
' Save the QR code with a logo as a JPEG image
QRWithLogo.SaveAsJpeg("Logoqr.jpeg")
上面的例子演示了如何使用IronBarcode生成帶有標誌圖像的QR碼。 CreateQrCodeWithLogo 函式允許我們建立嵌入標誌的QR碼,我們可以使用ChangeBarCodeColor方法改變條碼的顏色。
3.2 使用Aspose.BarCode
Aspose.BarCode可以用於條碼生成,我們可以使用以下程式碼片段生成不同的條碼型別:
using Aspose.BarCode.Generation;
// Create a BarcodeGenerator object and specify the barcode type and text
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "123456");
// Save the generated barcode as a JPEG image
generator.Save("output.jpg", BarCodeImageFormat.Jpeg);
using Aspose.BarCode.Generation;
// Create a BarcodeGenerator object and specify the barcode type and text
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.Code128, "123456");
// Save the generated barcode as a JPEG image
generator.Save("output.jpg", BarCodeImageFormat.Jpeg);
Imports Aspose.BarCode.Generation
' Create a BarcodeGenerator object and specify the barcode type and text
Private generator As New BarcodeGenerator(EncodeTypes.Code128, "123456")
' Save the generated barcode as a JPEG image
generator.Save("output.jpg", BarCodeImageFormat.Jpeg)
上面的程式碼使用BarcodeGenerator從Aspose.BarCode建立一個條碼。 我們通過構造函式指定條碼型別和文字。 Save方法允許我們以所需的格式如JPEG保存生成的條碼。
Aspose.BarCode還支持使用Parameters.Barcode.XDimension.Millimeters屬性自定義條的高度和寬度以指定線高和寬。
結果:
上面的圖片是這些庫的性能比較。 時間以毫秒計算。
4. 識別條碼
IronBarcode和Aspose.Barcodes可以讓我們識別來自不同圖像格式的條碼和它們所屬的型別。 讓我們詳細看看。
4.1 使用IronBarcode
IronBarcode幫助從不同的圖像格式中讀取條碼,可以用三種方式定義:作為字串、作為流,或作為JPEG、TIFF、Bitmap等圖像。以下範例是使用字串方法從圖像中讀取條碼。
using IronBarCode;
// Read a barcode from an image file
BarcodeResult QRResult = BarcodeReader.QuicklyReadOneBarcode("MyBarCode.jpg");
if (QRResult != null)
{
// Output the barcode value and type
Console.WriteLine(QRResult.Value);
Console.WriteLine(QRResult.BarcodeType);
}
using IronBarCode;
// Read a barcode from an image file
BarcodeResult QRResult = BarcodeReader.QuicklyReadOneBarcode("MyBarCode.jpg");
if (QRResult != null)
{
// Output the barcode value and type
Console.WriteLine(QRResult.Value);
Console.WriteLine(QRResult.BarcodeType);
}
Imports IronBarCode
' Read a barcode from an image file
Private QRResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("MyBarCode.jpg")
If QRResult IsNot Nothing Then
' Output the barcode value and type
Console.WriteLine(QRResult.Value)
Console.WriteLine(QRResult.BarcodeType)
End If
上述程式碼段使用BarcodeType(已識別條碼型別)的屬性。
4.2 使用Aspose.BarCode
在Aspose.BarCode for .NET中,條碼識別的來源可以用三種方式定義:作為圖像文件、一個流或一個位圖。下面提供了從JPEG格式的文件中讀取條碼的實施細節。
using Aspose.BarCode.BarCodeRecognition;
// Read a barcode using Aspose.BarCode
using (BarCodeReader reader = new BarCodeReader(@"MyBarCode.jpg"))
{
// Iterate through recognized barcodes
foreach (BarCodeResult result in reader.ReadBarCodes())
{
// Output the barcode type and text
Console.WriteLine("Type: " + result.CodeType);
Console.WriteLine("CodeText: " + result.CodeText);
}
}
using Aspose.BarCode.BarCodeRecognition;
// Read a barcode using Aspose.BarCode
using (BarCodeReader reader = new BarCodeReader(@"MyBarCode.jpg"))
{
// Iterate through recognized barcodes
foreach (BarCodeResult result in reader.ReadBarCodes())
{
// Output the barcode type and text
Console.WriteLine("Type: " + result.CodeType);
Console.WriteLine("CodeText: " + result.CodeText);
}
}
Imports Aspose.BarCode.BarCodeRecognition
' Read a barcode using Aspose.BarCode
Using reader As New BarCodeReader("MyBarCode.jpg")
' Iterate through recognized barcodes
For Each result As BarCodeResult In reader.ReadBarCodes()
' Output the barcode type and text
Console.WriteLine("Type: " & result.CodeType)
Console.WriteLine("CodeText: " & result.CodeText)
Next result
End Using
以上範例顯示了如何使用Aspose.BarCode讀取條碼。 BarCodeReader類用於使用路徑作為參數讀取條碼圖像。 然後foreach迴圈用於存取每個條碼結果,提供條碼型別和編碼的文字。
5. 結論
IronBarcode是幫助我們生成和識別條碼的最強大庫之一。 它也是生成和識別條碼的最快庫之一。 該程式庫由多個操作系統支持。 它支持多種條碼格式,並且易於建立。 使用者可以更改顏色、線高、寬度、條碼文字等。授權詳情可以在這裡找到。
Aspose.BarCode也是一個強大的生成和讀取不同圖像格式的條碼的程式庫。 我們可以使用各種圖像格式來讀取和建立。 Aspose還提供自定義條碼外觀的選項,如高度、寬度、條碼文字等。授權詳情可以在這裡找到。
與Aspose.BarCode相比,IronBarcode確實享有一些優勢。 在比較條碼識別和生成的處理時間時,IronBarcode更快。 IronBarcode還有各種屬性,不僅允許從不同圖像格式中讀取條碼,還允許從PDF文件中讀取條碼。 使用者可以在條碼和QR碼中新增圖像,這是許多庫中沒有的功能。
常見問題
Aspose.Barcode和IronBarcode之間有什麼不同?
Aspose.Barcode for .NET 支援超過60種條碼符號,並允許進行廣泛的客製化。 IronBarcode 以其速度和簡易性著稱,提供如從PDF中讀取條碼的功能和自動圖像預處理以提高準確性。
如何使用.NET程式庫在C#中生成條碼?
您可以透過呼叫BarcodeWriter.CreateBarcode方法來使用IronBarcode在C#中生成條碼,這使您能夠指定資料和條碼型別。條碼可以以多種格式保存,包括JPEG、PNG和PDF。
是否可以使用.NET程式庫從PDF中讀取條碼?
是的,IronBarcode提供從PDF中讀取條碼的功能,提供跨各種格式的條碼識別靈活性。
如何為.NET專案安裝條碼程式庫?
您可以透過Visual Studio中的NuGet Package Manager,使用Visual Studio命令行,或直接從NuGet或IronBarcode網站下載來在.NET專案中安裝IronBarcode。
使用IronBarcode進行條碼生成有哪些好處?
IronBarcode提供快速的處理時間,支援多種條碼標準,並包含進階功能,如自動圖像預處理和在條碼內嵌入圖像的能力。
我可以使用.NET程式庫客製化條碼的外觀嗎?
是的,Aspose.Barcode和IronBarcode都允許使用者客製化條碼外觀,包括顏色、大小和嵌入文字的調整。
使用.NET程式庫,我可以以哪些圖像格式保存條碼?
IronBarcode允許您以JPEG、TIFF、PNG、BMP、GIF等多種圖像格式保存條碼,還包含PDF和HTML格式。
有哪些平台與.NET條碼程式庫相容?
IronBarcode支援32位和64位.NET及.NET Core框架,適用於Web、雲端、桌面和控制台應用程式,無論是行動裝置還是桌面裝置。

