跳至页脚内容
与其他组件比较
IronBarcode 与 ZXing.NET 库的比较

A Comparison between IronBarcode and ZXing.NET

BarCode 扫描仪不一定总是适合我们的应用。 您可能已经有了条形码的数字图像,想知道它在英文文本中代表什么。 此外,这款扫描仪只能读取一维 BarCode,其中包含的数据量有限,只能在 Windows RT 类库中使用。 二维条形码(也称 QR 码)现在很常见,可以容纳更多的信息。

使用简单的 API 调用和几个编码步骤,就可以创建一个基于 C# 的应用程序来读取 BarCode。 支持 .NET 的应用程序可在 Windows、macOS 或 Linux 上运行,无需依赖任何第三方工具或 API。

本文将比较两个功能最强大的 .NET Core 应用程序库,以便以编程方式读取 BarCode。 这两个库是 IronBarcode 和 ZXing.NET。 我们将看到 IronBarcode for .NET 比 ZXing.NET 更强大、更稳健的地方。


什么是 ZXing.NET

ZXing.NET 是一个解码和生成条形码(如 QR Code、PDF 417、EAN、UPC、Aztec、Data Matrix、Codabar)的库。 ZXing 是 "斑马线 "的缩写,是一个基于 Java 的开源库,支持多种一维和二维条形码格式。

其基本特征如下:

  • 它能够存储 URL、联系方式、日历事件等内容。
  • 它是为 Java SE 应用程序量身定制的
  • 它允许通过意图集成 BarCode 扫描仪
  • 这是一个简单明了的谷歌眼镜应用程序

什么是 IronBarcode

IronBarcode 是一个 C# 库,允许程序员读取和生成条形码。 作为领先的条形码库,IronBarcode 支持各种一维和二维条形码,包括装饰(彩色和品牌)QR 码。 它支持 .NET Standard 和 Core 2 及更高版本,可在 Azure、Linux、macOS、Windows 和 Web 上跨平台使用。 IronBarcode 是 .NET 系统的知名类库或组件,可让 C#、VB.NET 和 F# 开发人员使用标准化编程语言工作。 它允许客户浏览扫描仪标签并创建新的标准化标签。 它对二维条形码和其他三维标准化条形码的处理效果特别好。

IronBarcode 现在支持二维条码。 它提供了优化这些代码的着色、样式和像素化的功能,并能为它们添加徽标,以便在印刷品或广告材料中使用。 该库还可以读取倾斜和变形的条形码,这是其他条形码软件可能无法读取的。

安装 IronBarcode 和 ZXing.NET.

安装 ZXing.NET.

要使用 ZXing.NET 库,请使用 NuGet 软件包管理器控制台在 ASP.NET Core 应用程序中安装以下两个软件包:

1.ZXing.Net

Install-Package ZXing.Net

2.ZXing.Net.Bindings.CoreCompat.System.Drawing。

Install-Package ZXing.Net.Bindings.CoreCompat.System.Drawing -Version 0.16.5-beta

或者,使用 NuGet 软件包管理器在您的项目中安装 ZXing.NET。 为此,请访问 Tools > NuGet Package Manager > Manage NuGet packages for solutions...,然后切换到 "Browse(浏览)"选项卡并搜索 "ZXing.NET"。

A Comparison between IronBarcode and Zxing.NET, Figure 1: ASP.NET Web应用程序

ASP.NET Web应用程序

IronBarcode 的安装

使用 NuGet 软件包管理器安装 IronBarcode,或直接从 产品网站下载 DLL。 IronBarcode 命名空间包含所有 IronBarcode 类。

可使用 Visual Studio 的 NuGet 软件包管理器安装 IronBarcode:软件包名称为 "Barcode"。

Install-Package BarCode

创建二维条形码

使用 ZXing.NET

首先,在项目文件的根目录下新建一个名为 "qrr "的文件夹。

然后,我们将继续创建 QR 文件,并将图像系统文件存储在 "qrr "文件夹中。

在控制器中,添加 GenerateFile() 方法,如下所示的源代码。

public ActionResult GenerateFile()
{
    return View();
}

[HttpPost]
public ActionResult GenerateFile(string qrText)
{
    Byte [] byteArray;
    var width = 250; // width of the QR Code
    var height = 250; // height of the QR Code
    var margin = 0;

    // BarcodeWriterPixelData acts as a QR code generator
    var qrCodeWriter = new ZXing.BarcodeWriterPixelData
    {
        Format = ZXing.BarcodeFormat.QR_CODE,
        Options = new QrCodeEncodingOptions
        {
            Height = height,
            Width = width,
            Margin = margin
        }
    };
    var pixelData = qrCodeWriter.Write(qrText);

    // creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
    using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
    {
        using (var ms = new MemoryStream())
        {
            var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            try
            {
                // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
            }
            finally
            {
                bitmap.UnlockBits(bitmapData);
           }

            // Save to folder
            string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
            bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);

            // Save to stream as PNG
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byteArray = ms.ToArray();
        }
    }
    return View(byteArray);
}
public ActionResult GenerateFile()
{
    return View();
}

[HttpPost]
public ActionResult GenerateFile(string qrText)
{
    Byte [] byteArray;
    var width = 250; // width of the QR Code
    var height = 250; // height of the QR Code
    var margin = 0;

    // BarcodeWriterPixelData acts as a QR code generator
    var qrCodeWriter = new ZXing.BarcodeWriterPixelData
    {
        Format = ZXing.BarcodeFormat.QR_CODE,
        Options = new QrCodeEncodingOptions
        {
            Height = height,
            Width = width,
            Margin = margin
        }
    };
    var pixelData = qrCodeWriter.Write(qrText);

    // creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
    using (var bitmap = new System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb))
    {
        using (var ms = new MemoryStream())
        {
            var bitmapData = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb);
            try
            {
                // we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
                System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length);
            }
            finally
            {
                bitmap.UnlockBits(bitmapData);
           }

            // Save to folder
            string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
            bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);

            // Save to stream as PNG
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
            byteArray = ms.ToArray();
        }
    }
    return View(byteArray);
}
Public Function GenerateFile() As ActionResult
	Return View()
End Function

<HttpPost>
Public Function GenerateFile(ByVal qrText As String) As ActionResult
	Dim byteArray() As Byte
	Dim width = 250 ' width of the QR Code
	Dim height = 250 ' height of the QR Code
	Dim margin = 0

	' BarcodeWriterPixelData acts as a QR code generator
	Dim qrCodeWriter = New ZXing.BarcodeWriterPixelData With {
		.Format = ZXing.BarcodeFormat.QR_CODE,
		.Options = New QrCodeEncodingOptions With {
			.Height = height,
			.Width = width,
			.Margin = margin
		}
	}
	Dim pixelData = qrCodeWriter.Write(qrText)

	' creating a PNG bitmap from the raw pixel data; if only black and white colors are used it makes no difference if the raw pixel data is BGRA oriented and the bitmap is initialized with RGB
	Using bitmap = New System.Drawing.Bitmap(pixelData.Width, pixelData.Height, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
		Using ms = New MemoryStream()
			Dim bitmapData = bitmap.LockBits(New System.Drawing.Rectangle(0, 0, pixelData.Width, pixelData.Height), System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppRgb)
			Try
				' we assume that the row stride of the bitmap is aligned to 4 byte multiplied by the width of the image
				System.Runtime.InteropServices.Marshal.Copy(pixelData.Pixels, 0, bitmapData.Scan0, pixelData.Pixels.Length)
			Finally
				bitmap.UnlockBits(bitmapData)
			End Try

			' Save to folder
			Dim fileGuid As String = Guid.NewGuid().ToString().Substring(0, 4)
			bitmap.Save(Server.MapPath("~/qrr") & "/file-" & fileGuid & ".png", System.Drawing.Imaging.ImageFormat.Png)

			' Save to stream as PNG
			bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
			byteArray = ms.ToArray()
		End Using
	End Using
	Return View(byteArray)
End Function
$vbLabelText   $csharpLabel

剩下的唯一改动就是将 QR 代码文件保存在 "qrr "文件夹内。 这可以通过下面的两行代码来实现。

string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);
string fileGuid = Guid.NewGuid().ToString().Substring(0, 4);
bitmap.Save(Server.MapPath("~/qrr") + "/file-" + fileGuid + ".png", System.Drawing.Imaging.ImageFormat.Png);
Dim fileGuid As String = Guid.NewGuid().ToString().Substring(0, 4)
bitmap.Save(Server.MapPath("~/qrr") & "/file-" & fileGuid & ".png", System.Drawing.Imaging.ImageFormat.Png)
$vbLabelText   $csharpLabel

接下来,您必须创建 GenerateFile 视图,并在其中包含以下代码。 GenerateFile 视图与索引视图相同。

@model Byte []
@using (Html.BeginForm(null, null, FormMethod.Post))
{
    <table>
        <tbody>
            <tr>
                <td>
                    <label>Enter text for creating QR Code</label>
                </td>
                <td>
                <input type="text" name="qrText" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button>Submit</button>
                </td>
            </tr>
        </tbody>
    </table>
}
@{
    if (Model != null)
    {
        <h3>QR Code Successfully Generated</h3>
        <img src="@String.Format("data:image/png;base64,{0}", Convert.ToBase64String(Model))" />
    }
}
@model Byte []
@using (Html.BeginForm(null, null, FormMethod.Post))
{
    <table>
        <tbody>
            <tr>
                <td>
                    <label>Enter text for creating QR Code</label>
                </td>
                <td>
                <input type="text" name="qrText" />
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <button>Submit</button>
                </td>
            </tr>
        </tbody>
    </table>
}
@{
    if (Model != null)
    {
        <h3>QR Code Successfully Generated</h3>
        <img src="@String.Format("data:image/png;base64,{0}", Convert.ToBase64String(Model))" />
    }
}
model Function [using](Html.BeginForm ByVal As (Nothing, Nothing, FormMethod.Post)) As Byte()
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: <table> <tbody> <tr> <td> <label> Enter text for creating QR Code</label> </td> <td> <input type="text" name="qrText" /> </td> </tr> <tr> <td colspan="2"> <button> Submit</button> </td> </tr> </tbody> </table>
	"qrText" /> </td> </tr> (Of tr) <td colspan="2"> (Of button) Submit</button> </td> </tr> </tbody> </table>
'INSTANT VB WARNING: An assignment within expression was extracted from the following statement:
'ORIGINAL LINE: <table> <tbody> <tr> <td> <label> Enter text for creating QR Code</label> </td> <td> <input type="text" name="qrText" /> </td> </tr> <tr> <td colspan
	"text" name="qrText" /> </td> </tr> (Of tr) <td colspan
	(Of table) (Of tbody) (Of tr) (Of td) (Of label) Enter text for creating QR Code</label> </td> (Of td) <input type="text" name
End Function
@
If True Then
	If Model IsNot Nothing Then
'INSTANT VB WARNING: Instant VB cannot determine whether both operands of this division are integer types - if they are then you should use the VB integer division operator:
		(Of h3) QR Code Successfully Generated</h3> <img src="@String.Format("data:image/png
		base64,
		If True Then
			0
		End If
		", Convert.ToBase64String(Model))" />
	End If
End If
$vbLabelText   $csharpLabel

在文本框中输入任何值,然后单击 "提交 "按钮。 QR 代码将生成并以 .PNG 文件格式保存在 "qrr "文件夹中。

A Comparison between IronBarcode and ZXing.NET, Figure 2: 二维码生成器

二维码生成器

A Comparison between IronBarcode and ZXing.NET, Figure 3: 显示的 QR 代码文件

显示的 QR 代码文件

支持的 BarCode 格式

IronBarcode 支持多种常用条码格式,包括

  • 带有徽标和颜色的 QR 码(包括装饰码和品牌码)
  • 多格式条形码,包括 Aztec、Data Matrix、CODE 93、CODE 128、RSS Expanded Databar、UPS MaxiCode 和 USPS、IMB (OneCode) 条形码
  • RSS-14 和 PDF-417 堆叠线性条形码
  • UPCA、UPCE、EAN-8、EAN-13、Codabar、ITF、MSI 和 Plessey 是传统的数字条形码格式。

创建和保存条形码

using IronBarCode;
// Create a barcode and save it in various formats
var MyBarCode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");

// Convert barcode to different image formats and obtain binary data
System.Drawing.Image MyBarCodeImage = MyBarCode.Image;
System.Drawing.Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
string DataURL = MyBarCode.ToDataUrl();
string ImgTagForHTML = MyBarCode.ToHtmlTag();
byte[] PngBytes = MyBarCode.ToPngBinaryData();

// Save barcode in PDF stream
using (System.IO.Stream PdfStream = MyBarCode.ToPdfStream())
{
    // The Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
}

// Stamp barcode onto an existing PDF at a specific position
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50);
using IronBarCode;
// Create a barcode and save it in various formats
var MyBarCode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128);
MyBarCode.SaveAsImage("MyBarCode.png");
MyBarCode.SaveAsGif("MyBarCode.gif");
MyBarCode.SaveAsHtmlFile("MyBarCode.html");
MyBarCode.SaveAsJpeg("MyBarCode.jpg");
MyBarCode.SaveAsPdf("MyBarCode.Pdf");
MyBarCode.SaveAsPng("MyBarCode.png");
MyBarCode.SaveAsTiff("MyBarCode.tiff");
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp");

// Convert barcode to different image formats and obtain binary data
System.Drawing.Image MyBarCodeImage = MyBarCode.Image;
System.Drawing.Bitmap MyBarCodeBitmap = MyBarCode.ToBitmap();
string DataURL = MyBarCode.ToDataUrl();
string ImgTagForHTML = MyBarCode.ToHtmlTag();
byte[] PngBytes = MyBarCode.ToPngBinaryData();

// Save barcode in PDF stream
using (System.IO.Stream PdfStream = MyBarCode.ToPdfStream())
{
    // The Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
}

// Stamp barcode onto an existing PDF at a specific position
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50);
Imports IronBarCode
' Create a barcode and save it in various formats
Private MyBarCode = BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeEncoding.Code128)
MyBarCode.SaveAsImage("MyBarCode.png")
MyBarCode.SaveAsGif("MyBarCode.gif")
MyBarCode.SaveAsHtmlFile("MyBarCode.html")
MyBarCode.SaveAsJpeg("MyBarCode.jpg")
MyBarCode.SaveAsPdf("MyBarCode.Pdf")
MyBarCode.SaveAsPng("MyBarCode.png")
MyBarCode.SaveAsTiff("MyBarCode.tiff")
MyBarCode.SaveAsWindowsBitmap("MyBarCode.bmp")

' Convert barcode to different image formats and obtain binary data
Dim MyBarCodeImage As System.Drawing.Image = MyBarCode.Image
Dim MyBarCodeBitmap As System.Drawing.Bitmap = MyBarCode.ToBitmap()
Dim DataURL As String = MyBarCode.ToDataUrl()
Dim ImgTagForHTML As String = MyBarCode.ToHtmlTag()
Dim PngBytes() As Byte = MyBarCode.ToPngBinaryData()

' Save barcode in PDF stream
Using PdfStream As System.IO.Stream = MyBarCode.ToPdfStream()
	' The Stream barcode image output also works for GIF, JPEG, PDF, PNG, BMP and TIFF
End Using

' Stamp barcode onto an existing PDF at a specific position
MyBarCode.StampToExistingPdfPage("ExistingPDF.pdf", 1, 200, 50)
$vbLabelText   $csharpLabel

另一方面,ZXing 是一个基于 Java 的开源一维/二维条形码图像处理库。 支持 UPC-A、UPC-E、EAN-8、Code 93、Code 128、QR Code、Data Matrix、Aztec、PDF 417 和其他条形码格式。

A Comparison between IronBarcode and Zxing.NET, Figure 4: 支持的条码格式

支持的条码格式

使用 IronBarcode 创建 QR 码文件

要使用 IronBarcode 创建 QR 代码,我们可以使用 QRCodeWriter 类,而不是 BarcodeWriter 类。 本课介绍了创建 QR 代码的一些新颖而有趣的功能。 它使我们能够设置 QR 纠错级别,让您在 QR 代码的大小和可读性之间取得平衡。

using IronBarCode;
// Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png");
using IronBarCode;
// Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png");
Imports IronBarCode
' Generate a simple QR Code image and save as PNG
QRCodeWriter.CreateQrCode("hello world", 500, QRCodeWriter.QrErrorCorrectionLevel.Medium).SaveAsPng("MyQR.png")
$vbLabelText   $csharpLabel

通过纠错,我们可以明确在实际情况下阅读二维码的难易程度。 纠错级别越高,二维码越大,像素越多,复杂度越高。 在下图中,我们看到了二维码文件的显示。

A Comparison between IronBarcode and ZXing.NET, Figure 5: 支持的条码格式

二维码图片

我们首先通过IronBarcode.BarcodeWriterEncoding枚举指定条形码的值和条形码格式。 然后我们可以将其保存为图像、 System.Drawing.Image或 Bitmap 代码对象。

using IronBarCode;
using System.Diagnostics;

// Generate a simple BarCode image and save as PNG using the following namespaces
GeneratedBarcode MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);
MyBarCode.SaveAsPng("MyBarCode.png");

// This line opens the image in your default image viewer
Process.Start("MyBarCode.png");
using IronBarCode;
using System.Diagnostics;

// Generate a simple BarCode image and save as PNG using the following namespaces
GeneratedBarcode MyBarCode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128);
MyBarCode.SaveAsPng("MyBarCode.png");

// This line opens the image in your default image viewer
Process.Start("MyBarCode.png");
Imports IronBarCode
Imports System.Diagnostics

' Generate a simple BarCode image and save as PNG using the following namespaces
Private MyBarCode As GeneratedBarcode = IronBarcode.BarcodeWriter.CreateBarcode("https://ironsoftware.com/csharp/barcode", BarcodeWriterEncoding.Code128)
MyBarCode.SaveAsPng("MyBarCode.png")

' This line opens the image in your default image viewer
Process.Start("MyBarCode.png")
$vbLabelText   $csharpLabel
A Comparison between IronBarcode and ZXing.NET, Figure 6: 在 C# 示例中创建 BarCode 图像

在 C# 示例中创建 BarCode 图像

IronBarcode 还支持对二维码进行样式设置,例如将徽标图形放置在图像的正中心并使其与网格对齐。 它还可以涂上颜色,以匹配特定的品牌或图形标识。

为了进行测试,请在下面的代码示例中创建一个徽标,看看使用QRCodeWriter.CreateQRCodeWithLogo方法有多么简单。

using IronBarCode;

// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
using IronBarCode;

// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);
Imports IronBarCode

' Adding a Logo
Private MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500)
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen)
$vbLabelText   $csharpLabel
A Comparison between IronBarcode and ZXing.NET, Figure 7: 使用徽标图像创建 QR 代码

使用徽标图像创建 QR 代码

最后,我们将生成的 QR 代码保存为 PDF 文件。为方便起见,最后一行代码将 QR 代码保存为 HTML 文件。

using IronBarCode;

// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);

// Save as PDF
MyQRWithLogo.SaveAsPdf("MyQRWithLogo.pdf");

// Also Save as HTML
MyQRWithLogo.SaveAsHtmlFile("MyQRWithLogo.html");
using IronBarCode;

// Adding a Logo
var MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500);
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen);

// Save as PDF
MyQRWithLogo.SaveAsPdf("MyQRWithLogo.pdf");

// Also Save as HTML
MyQRWithLogo.SaveAsHtmlFile("MyQRWithLogo.html");
Imports IronBarCode

' Adding a Logo
Private MyQRWithLogo = QRCodeWriter.CreateQrCodeWithLogo("https://ironsoftware.com/csharp/barcode/", "visual-studio-logo.png", 500)
MyQRWithLogo.ChangeBarCodeColor(System.Drawing.Color.DarkGreen)

' Save as PDF
MyQRWithLogo.SaveAsPdf("MyQRWithLogo.pdf")

' Also Save as HTML
MyQRWithLogo.SaveAsHtmlFile("MyQRWithLogo.html")
$vbLabelText   $csharpLabel

下面,我们将看到如何仅用一行代码就创建、样式化和导出一个 BarCode。

IronBarcode 包含一个类似于 System.Linq 的流畅 API。 我们创建一个 BarCode,设置其边距,并通过链式方法调用将其单行导出为位图。 这可能会非常有用,并使代码更容易阅读。

using IronBarCode;
using System.Drawing;

// Fluent API for Barcode image generation
string MyValue = "https://ironsoftware.com/csharp/barcode";
Bitmap BarcodeBmp = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417)
    .ResizeTo(300, 200)
    .SetMargins(100)
    .ToBitmap();
using IronBarCode;
using System.Drawing;

// Fluent API for Barcode image generation
string MyValue = "https://ironsoftware.com/csharp/barcode";
Bitmap BarcodeBmp = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417)
    .ResizeTo(300, 200)
    .SetMargins(100)
    .ToBitmap();
Imports IronBarCode
Imports System.Drawing

' Fluent API for Barcode image generation
Private MyValue As String = "https://ironsoftware.com/csharp/barcode"
Private BarcodeBmp As Bitmap = IronBarcode.BarcodeWriter.CreateBarcode(MyValue, BarcodeEncoding.PDF417).ResizeTo(300, 200).SetMargins(100).ToBitmap()
$vbLabelText   $csharpLabel

因此,PDF417 条形码的 System.Drawing.Image 显示如下所示:

A Comparison between IronBarcode and ZXing.NET, Figure 8: 在 C# 中简单流畅地生成 PDF417 BarCode

在 C# 中简单流畅地生成 PDF417 BarCode

读取 QR 代码文件

使用 IronBarcode 阅读 QR 码

当您将 IronBarcode for .NET 类库与 .NET 条码阅读器结合使用时,阅读条码或 QR 码将变得轻而易举。 在第一个示例中,我们可以看到如何仅使用一行代码读取条形码。

A Comparison between IronBarcode and ZXing.NET, Figure 9: 使用 C# 扫描 Code128 BarCode 图像

使用 C# 扫描 Code128 BarCode 图像

我们可以获取 BarCode 的值、图像、编码类型和二进制数据(如果有),然后将其输出到控制台。

using IronBarCode;
using System;

// Read a barcode or QR code from an image
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png");
if (Result != null && Result.Text == "https://ironsoftware.com/csharp/barcode/")
{
    Console.WriteLine("GetStarted was a success.  Read Value: " + Result.Text);
}
using IronBarCode;
using System;

// Read a barcode or QR code from an image
BarcodeResult Result = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png");
if (Result != null && Result.Text == "https://ironsoftware.com/csharp/barcode/")
{
    Console.WriteLine("GetStarted was a success.  Read Value: " + Result.Text);
}
Imports IronBarCode
Imports System

' Read a barcode or QR code from an image
Private Result As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("GetStarted.png")
If Result IsNot Nothing AndAlso Result.Text = "https://ironsoftware.com/csharp/barcode/" Then
	Console.WriteLine("GetStarted was a success.  Read Value: " & Result.Text)
End If
$vbLabelText   $csharpLabel

阅读 PDF 内部的 BarCode.

我们将研究如何读取扫描的 PDF 文档,并通过几行代码找到所有的一维 BarCode。

正如您所看到的,这与从单个文档中读取单个条形码非常相似,只不过我们现在知道了发现条形码的页码。

using IronBarCode;
using System;
using System.Drawing;

// Multiple barcodes may be scanned up from a single document or image. A PDF document may also be used as the input image
PagedBarcodeResult[] PDFResults = BarcodeReader.ReadBarcodesFromPdf("MultipleBarcodes.pdf");

// Work with the results
foreach (var PageResult in PDFResults)
{
    string Value = PageResult.Value;
    int PageNum = PageResult.PageNumber;
    System.Drawing.Bitmap Img = PageResult.BarcodeImage;
    BarcodeEncoding BarcodeType = PageResult.BarcodeType;
    byte[] Binary = PageResult.BinaryValue;
    Console.WriteLine(PageResult.Value + " on page " + PageNum);
}
using IronBarCode;
using System;
using System.Drawing;

// Multiple barcodes may be scanned up from a single document or image. A PDF document may also be used as the input image
PagedBarcodeResult[] PDFResults = BarcodeReader.ReadBarcodesFromPdf("MultipleBarcodes.pdf");

// Work with the results
foreach (var PageResult in PDFResults)
{
    string Value = PageResult.Value;
    int PageNum = PageResult.PageNumber;
    System.Drawing.Bitmap Img = PageResult.BarcodeImage;
    BarcodeEncoding BarcodeType = PageResult.BarcodeType;
    byte[] Binary = PageResult.BinaryValue;
    Console.WriteLine(PageResult.Value + " on page " + PageNum);
}
Imports IronBarCode
Imports System
Imports System.Drawing

' Multiple barcodes may be scanned up from a single document or image. A PDF document may also be used as the input image
Private PDFResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromPdf("MultipleBarcodes.pdf")

' Work with the results
For Each PageResult In PDFResults
	Dim Value As String = PageResult.Value
	Dim PageNum As Integer = PageResult.PageNumber
	Dim Img As System.Drawing.Bitmap = PageResult.BarcodeImage
	Dim BarcodeType As BarcodeEncoding = PageResult.BarcodeType
	Dim Binary() As Byte = PageResult.BinaryValue
	Console.WriteLine(PageResult.Value & " on page " & PageNum)
Next PageResult
$vbLabelText   $csharpLabel

您将获得 PDF 中包含所有位图 BarCode 的结果数据。

A Comparison between IronBarcode and ZXing.NET, Figure 10: 阅读存储在 PDF 结果中的 BarCode

阅读存储在 PDF 结果中的 BarCode

从 GIF 和 TIFF 读取条形码

using IronBarCode;
using System;

// Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
PagedBarcodeResult[] MultiFrameResults = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels);
foreach (var PageResult in MultiFrameResults)
{
    // Process each page result
}
using IronBarCode;
using System;

// Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
PagedBarcodeResult[] MultiFrameResults = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels);
foreach (var PageResult in MultiFrameResults)
{
    // Process each page result
}
Imports IronBarCode
Imports System

' Multi-frame TIFF and GIF images can also be scanned, and multiple threads will be used automatically in the background for improved performance
Private MultiFrameResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesFromMultiFrameTiff("Multiframe.tiff", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.High, BarcodeReader.BarcodeImageCorrection.MediumCleanPixels)
For Each PageResult In MultiFrameResults
	' Process each page result
Next PageResult
$vbLabelText   $csharpLabel
A Comparison between IronBarcode and ZXing.NET, Figure 11: 从多帧 TIFF 图像中读取 BarCode

从多帧 TIFF 图像中读取 BarCode

以下示例展示了如何从扫描的 PDF 中读取 QR 码和 PDF-417 条形码。 我们设定了适当的条形码旋转校正和条形码图像校正级别,以便在不造成明显性能损失的情况下轻微清理文档。

using IronBarCode;
using System;

// PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
var ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels);

// Work with the results
foreach (var PageResult in ScanResults)
{
    string Value = PageResult.Value;
    //...
}
using IronBarCode;
using System;

// PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
var ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels);

// Work with the results
foreach (var PageResult in ScanResults)
{
    string Value = PageResult.Value;
    //...
}
Imports IronBarCode
Imports System

' PDF documents can also be scanned, and multiple threads will be used automatically in the background for improved performance
Private ScanResults = BarcodeReader.ReadBarcodesFromPdf("Scan.pdf", BarcodeEncoding.All, BarcodeReader.BarcodeRotationCorrection.Low, BarcodeReader.BarcodeImageCorrection.LightlyCleanPixels)

' Work with the results
For Each PageResult In ScanResults
	Dim Value As String = PageResult.Value
	'...
Next PageResult
$vbLabelText   $csharpLabel
A Comparison between IronBarcode and ZXing.NET, Figure 12: 从扫描的 PDF 文档中读取 BarCode

从扫描的 PDF 文档中读取 BarCode

从位图图像读取损坏的 QR 代码

下面的示例显示,该 C# 条码库甚至可以读取损坏的条码缩略图。

条形码缩略图尺寸会自动更正。 C# 中的 IronBarcode 使文件可读。

阅读器方法可自动检测出小于合法条形码的条形码图像,并将其放大。 他们要清除与缩略图工作相关的所有数字噪音,使缩略图重新具有可读性。

using IronBarCode;

// Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128);
using IronBarCode;

// Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
BarcodeResult SmallResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128);
Imports IronBarCode

' Small or 'Thumbnail' barcode images are automatically detected by IronBarcode and corrected wherever possible even if they have much digital noise.
Private SmallResult As BarcodeResult = BarcodeReader.QuicklyReadOneBarcode("ThumbnailOfBarcode.gif", BarcodeEncoding.Code128)
$vbLabelText   $csharpLabel
A Comparison between IronBarcode and ZXing.NET, Figure 13: 自动校正 BarCode 缩略图尺寸

自动校正 BarCode 缩略图尺寸

从不规则图像中读取 BarCode.

在现实场景中,我们可能希望从不完美的图像中读取 BarCode。 在翻译过程中,可能会出现图像歪斜或照片有数字噪点的情况。大多数开源 .NET 条码生成和读取库都不可能做到这一点。 而 IronBarcode 则让从不完美的图像中读取条形码变得轻而易举。

现在我们来看看 ReadASingleBarcode 方法。 通过其 RotationCorrection 参数,IronBarcode 尝试从不完美的数字样本中去除倾斜并读取条形码。

using IronBarCode;
using System;
using System.Drawing;

// All BarcodeResult.Read methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
// * RotationCorrection   e.g BarcodeReader.BarcodeRotationCorrection.Extreme un-rotates and removes perspective from barcode images.
// * ImageCorrection      e.g BarcodeReader.BarcodeImageCorrection.DeepCleanPixels separates barcodes from background imagery and digital noise.
// * BarcodeEncoding      e.g. BarcodeEncoding.Code128,  Setting a specific Barcode format improves speed and reduces the risk of false positive results

// Example with a photo image
var PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
string Value = PhotoResult.Value;
System.Drawing.Bitmap Img = PhotoResult.BarcodeImage;
BarcodeEncoding BarcodeType = PhotoResult.BarcodeType;
byte[] Binary = PhotoResult.BinaryValue;
Console.WriteLine(PhotoResult.Value);
using IronBarCode;
using System;
using System.Drawing;

// All BarcodeResult.Read methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
// * RotationCorrection   e.g BarcodeReader.BarcodeRotationCorrection.Extreme un-rotates and removes perspective from barcode images.
// * ImageCorrection      e.g BarcodeReader.BarcodeImageCorrection.DeepCleanPixels separates barcodes from background imagery and digital noise.
// * BarcodeEncoding      e.g. BarcodeEncoding.Code128,  Setting a specific Barcode format improves speed and reduces the risk of false positive results

// Example with a photo image
var PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels);
string Value = PhotoResult.Value;
System.Drawing.Bitmap Img = PhotoResult.BarcodeImage;
BarcodeEncoding BarcodeType = PhotoResult.BarcodeType;
byte[] Binary = PhotoResult.BinaryValue;
Console.WriteLine(PhotoResult.Value);
Imports IronBarCode
Imports System
Imports System.Drawing

' All BarcodeResult.Read methods provide the developer with control to correct image and photograph correction and straightening rotation and perspective from skewed images
' * RotationCorrection   e.g BarcodeReader.BarcodeRotationCorrection.Extreme un-rotates and removes perspective from barcode images.
' * ImageCorrection      e.g BarcodeReader.BarcodeImageCorrection.DeepCleanPixels separates barcodes from background imagery and digital noise.
' * BarcodeEncoding      e.g. BarcodeEncoding.Code128,  Setting a specific Barcode format improves speed and reduces the risk of false positive results

' Example with a photo image
Private PhotoResult = BarcodeReader.ReadASingleBarcode("Photo.png", BarcodeEncoding.Code128, BarcodeReader.BarcodeRotationCorrection.Medium, BarcodeReader.BarcodeImageCorrection.DeepCleanPixels)
Private Value As String = PhotoResult.Value
Private Img As System.Drawing.Bitmap = PhotoResult.BarcodeImage
Private BarcodeType As BarcodeEncoding = PhotoResult.BarcodeType
Private Binary() As Byte = PhotoResult.BinaryValue
Console.WriteLine(PhotoResult.Value)
$vbLabelText   $csharpLabel
A Comparison between IronBarcode and ZXing.NET, Figure 14: 从手机摄像头读取条形码

从手机摄像头读取条形码

IronBarcode还可以同时读取多个条形码。当我们创建文档列表并使用条形码读取器读取多个文档时,IronBarcode的性能会更佳。 条形码扫描过程的ReadBarcodesMultithreaded方法使用多个线程,并且可能使用 CPU 的所有核心,这比一次读取一个条形码要快得多。

using IronBarCode;

// The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs. All threads are automatically managed by IronBarcode.
var ListOfDocuments = new[] { "Image1.png", "image2.JPG", "image3.pdf" };
PagedBarcodeResult[] BatchResults = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments);

// Work with the results
foreach (var Result in BatchResults)
{
    string Value = Result.Value;
    //...
}
using IronBarCode;

// The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs. All threads are automatically managed by IronBarcode.
var ListOfDocuments = new[] { "Image1.png", "image2.JPG", "image3.pdf" };
PagedBarcodeResult[] BatchResults = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments);

// Work with the results
foreach (var Result in BatchResults)
{
    string Value = Result.Value;
    //...
}
Imports IronBarCode

' The BarcodeResult.ReadBarcodesMultiThreaded method allows for faster barcode scanning of multiple images or PDFs. All threads are automatically managed by IronBarcode.
Private ListOfDocuments = { "Image1.png", "image2.JPG", "image3.pdf" }
Private BatchResults() As PagedBarcodeResult = BarcodeReader.ReadBarcodesMultiThreaded(ListOfDocuments)

' Work with the results
For Each Result In BatchResults
	Dim Value As String = Result.Value
	'...
Next Result
$vbLabelText   $csharpLabel

使用 ZXing.NET 阅读和解码 QR 代码。

要读取 QR 代码文件,请在控制器中添加 ViewFile 操作方法,如下所示。

public ActionResult ViewFile()
{
    List<KeyValuePair<string, string>> fileData = new List<KeyValuePair<string, string>>();
    KeyValuePair<string, string> data;

    string[] files = Directory.GetFiles(Server.MapPath("~/qrr"));
    foreach (string file in files)
    {
        // Create a barcode reader instance
        IBarcodeReader reader = new BarcodeReader();

        // Load a bitmap
        var barcodeBitmap = (Bitmap)Image.FromFile(Server.MapPath("~/qrr") + "/" + Path.GetFileName(file));

        // Detect and decode the barcode inside the bitmap
        var result = reader.Decode(barcodeBitmap);

        // Do something with the result
        data = new KeyValuePair<string, string>(result.ToString(), "/QR/" + Path.GetFileName(file));
        fileData.Add(data);
    }
    return View(fileData);
}
public ActionResult ViewFile()
{
    List<KeyValuePair<string, string>> fileData = new List<KeyValuePair<string, string>>();
    KeyValuePair<string, string> data;

    string[] files = Directory.GetFiles(Server.MapPath("~/qrr"));
    foreach (string file in files)
    {
        // Create a barcode reader instance
        IBarcodeReader reader = new BarcodeReader();

        // Load a bitmap
        var barcodeBitmap = (Bitmap)Image.FromFile(Server.MapPath("~/qrr") + "/" + Path.GetFileName(file));

        // Detect and decode the barcode inside the bitmap
        var result = reader.Decode(barcodeBitmap);

        // Do something with the result
        data = new KeyValuePair<string, string>(result.ToString(), "/QR/" + Path.GetFileName(file));
        fileData.Add(data);
    }
    return View(fileData);
}
Public Function ViewFile() As ActionResult
	Dim fileData As New List(Of KeyValuePair(Of String, String))()
	Dim data As KeyValuePair(Of String, String)

	Dim files() As String = Directory.GetFiles(Server.MapPath("~/qrr"))
	For Each file As String In files
		' Create a barcode reader instance
		Dim reader As IBarcodeReader = New BarcodeReader()

		' Load a bitmap
		Dim barcodeBitmap = CType(Image.FromFile(Server.MapPath("~/qrr") & "/" & Path.GetFileName(file)), Bitmap)

		' Detect and decode the barcode inside the bitmap
		Dim result = reader.Decode(barcodeBitmap)

		' Do something with the result
		data = New KeyValuePair(Of String, String)(result.ToString(), "/QR/" & Path.GetFileName(file))
		fileData.Add(data)
	Next file
	Return View(fileData)
End Function
$vbLabelText   $csharpLabel
A Comparison between IronBarcode and ZXing.NET, Figure 15: 阅读和解码 QR 代码

阅读和解码 QR 代码

A Comparison between IronBarcode and ZXing.NET, Figure 16: 解码 QR 代码

解码 QR 代码

解码位图中的 BarCode.

using ZXing;
using System.Drawing;

// Create a barcode reader instance
BarcodeReader reader = new BarcodeReader();

// Load a bitmap
var barcodeBitmap = (Bitmap)Image.FromFile("C:\\sample-barcode-image.png");

// Detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);

// Do something with the result
if (result != null)
{
    txtDecoderType.Text = result.BarcodeFormat.ToString();
    txtDecoderContent.Text = result.Text;
}
using ZXing;
using System.Drawing;

// Create a barcode reader instance
BarcodeReader reader = new BarcodeReader();

// Load a bitmap
var barcodeBitmap = (Bitmap)Image.FromFile("C:\\sample-barcode-image.png");

// Detect and decode the barcode inside the bitmap
var result = reader.Decode(barcodeBitmap);

// Do something with the result
if (result != null)
{
    txtDecoderType.Text = result.BarcodeFormat.ToString();
    txtDecoderContent.Text = result.Text;
}
Imports ZXing
Imports System.Drawing

' Create a barcode reader instance
Private reader As New BarcodeReader()

' Load a bitmap
Private barcodeBitmap = CType(Image.FromFile("C:\sample-barcode-image.png"), Bitmap)

' Detect and decode the barcode inside the bitmap
Private result = reader.Decode(barcodeBitmap)

' Do something with the result
If result IsNot Nothing Then
	txtDecoderType.Text = result.BarcodeFormat.ToString()
	txtDecoderContent.Text = result.Text
End If
$vbLabelText   $csharpLabel

中兴解码器在线

ZXing Decoder Online 是一款支持解码的在线条形码和二维码扫描器。 上传 PNG 或其他格式的二维码图片,它就会开始解码。 同样,您也可以为任何数据生成 QR 代码。 大多数情况下,这些信息将是您希望编码到 QR 代码中的 URL 或文本。

导航至 ZXing Decoder 网站。

A Comparison between IronBarcode and ZXing.NET, Figure 17: 解码 QR 代码

ZXing 解码器网站

A Comparison between IronBarcode and ZXing.NET, Figure 18: 解码 QR 代码

ZXing 解码结果

定价和许可

ZXing.NET 库是一个免费的开源库,允许您构建条形码读取应用程序,采用 Apache License 2.0 许可,允许在适当注明出处的情况下免费用于商业用途。

我们免费提供 IronBarcode 的开发人员许可证。 IronBarcode 有一个独特的定价方案:Lite bundle 起价为 $liteLicense,没有额外费用。 也可以再次分发 SaaS 和 OEM 项目。 每个许可证包括永久许可证、开发/分期/生产有效性、30 天退款保证以及一年的软件支持和升级(一次性购买)。 请访问此页面查看 IronBarcode 的完整定价和许可信息。

为什么选择 IronBarcode?

IronBarcode 包括一个易于使用的 API,供开发人员在 .NET 中读写条形码,从而优化了准确性和实际使用案例中的低错误率。

例如,BarcodeWriter 类将验证和纠正 UPCA 和 UPCE 条形码上的 "校验和"。 此外,对于太短而无法输入特定数字格式的数字,还要进行 "零填充"。 如果您的数据与指定的数据格式不兼容,IronBarcode 将通知开发者可使用更合适的条码格式。

IronBarcode 擅长在扫描条形码或从照片图像中读取条形码时读取条形码,换句话说,在图像图形不完美且不是机器生成的截图时读取条形码。

IronBarcode 与 ZXing.NET 有何不同?

IronBarcode for .NET 由 ZXing.NET (Zebra Crossing) 核心构建,处理能力有所提高。 与 ZXing.NET Core 库相比,它带有易于使用的 API,错误率较低。 不仅如此,IronBarcode for .NET 还支持比通常的 ZXing.NET 库所支持的更广泛的条形码格式。

IronBarcode 是 ZXing.NET 的改良版,为用户提供了商业使用平台,并可在多个平台上使用同一软件包。 它还提供全面的技术支持,随时准备为您提供所需的帮助。

IronBarcode 包括自动旋转、透视校正和数字噪声校正,并能检测图像中编码的条形码类型。

结论

总之,IronBarcode 是一款多功能的 .NET 软件库和 C# QR Code 生成器,可用于读取各种条形码格式,无论是截图、照片、扫描还是其他不完美的真实世界图像。

IronBarcode 是创建和识别条形码最有效的库之一。 在创建和识别 BarCode 方面,它也是最迅捷的库之一。 该库可以与不同的操作系统兼容。 它易于设计,支持多种条形码格式。 此外,还要支持各种符号、格式和字符。

ZXing.NET 条形码是一个功能强大的库,可生成和识别各种图像格式的条形码。 我们可以阅读和创建各种格式的图像。 ZXing.NET 还允许您更改条形码的外观,改变其高度、宽度、条形码文本等。

与 ZXing.NET 相比,IronBarcode 软件包提供可靠的许可和支持。 IronBarcode 费用为 $liteLicense。 虽然 ZXing 是免费开源的,但 IronBarcode 提供全面的商业支持和专业维护。 除了比 ZXing.NET 更为灵活之外,Iron BarCode 解决方案还具有更多功能。 由此可见,IronBarcode 比 ZXing.NET 更具优势。

在比较识别和生成条形码的处理时间时,IronBarcode 优于 ZXing.NET。 IronBarcode 还具有多种特性,使我们能够从不同的图像格式和 PDF 文档中读取条形码。 它还允许我们在条形码或 QR 码内包含图像,这是其他任何库都不具备的。

IronBarcode 在开发初期是免费的。 您可以获取免费试用版,用于生产级或商业用途。 根据开发人员的要求,IronBarcode 提供三个定价等级。 您可以选择最能满足您需求的解决方案。 现在,您可以用购买两件 Iron Software 产品的价格获得五件 Iron Software 产品的套件。 请访问此网站了解更多信息。

请注意ZXing.NET 是其各自所有者的注册商标。 本网站与 ZXing.NET 无关,也未经 ZXing.NET 认可或赞助。 所有产品名称、徽标和品牌均为各自所有者的财产。 比较仅供参考,反映的是撰写时的公开信息。

常见问题解答

如何在 C# 中生成 QR 码?

您可以通过使用 IronBarcode 的 `BarcodeWriter` 类,在 C# 中生成 QR 码。只需定义 QR 码内容,自定义颜色和大小等选项,然后调用 `Write` 方法生成 QR 码。

是什么使 IronBarcode 比 ZXing.NET 更强大?

IronBarcode 提供增强的功能,例如支持更多条形码格式,先进的图像处理功能,如旋转和透视校正,以及能够创建带有徽标和颜色的装饰性 QR 码。它还具有跨平台兼容性并提供商业支持。

我可以使用 IronBarcode 从有缺陷的图像中读取条形码吗?

可以,IronBarcode 能够通过旋转校正、透视校正和数字噪声减少等功能,从有缺陷的图像中读取条形码,使其在扫描或摄影图像中有效。

在 C# 中读取条形码的步骤是什么?

要在 C# 中读取条形码,请使用 IronBarcode 的 `BarcodeReader` 类。使用 `BarcodeReader.QuicklyReadOneBarcode` 方法加载包含条形码的图像,该方法会解码并返回识别出的条形码内容。

IronBarcode 如何处理跨平台兼容性?

IronBarcode 支持跨平台兼容性,适用于 Windows、macOS、Linux 和 Azure,允许您将条形码生成和读取功能集成到各种 .NET 应用程序中,无需第三方依赖。

IronBarcode 提供哪些 QR 码自定义选项?

IronBarcode 允许通过调整颜色、添加品牌徽标以及配置错误校正级别来定制 QR 码,以平衡尺寸和可读性,为各种美学和功能需求提供灵活性。

使用 IronBarcode 开发商业应用是否需要付费授权?

IronBarcode 提供不同的授权选项,包括适合商业应用的永久授权。这和免费但对商业使用有限制的 ZXing.NET 形成对比。

使用条形码库时常见的故障排除场景是什么?

常见问题可能包括由于图像质量差导致条形码识别不正确、不支持的条形码格式或配置错误。IronBarcode 的高级图像处理可以帮助减轻某些识别问题。

为什么有人可能会选择 IronBarcode 而不是 ZXing.NET 进行条形码处理?

IronBarcode 提供更强大的 API、更好的错误处理、广泛的条形码格式支持以及生成视觉定制 QR 码的功能,所有这些都具有商业授权和专业支持的额外好处。

如何在 .NET 项目中安装 IronBarcode?

您可以通过在 Visual Studio 中搜索 'IronBarcode' 并将其添加到项目中,使用 NuGet 包管理器在 .NET 项目中安装 IronBarcode,确保轻松集成和更新。

Jordi Bardia
软件工程师
Jordi 最擅长 Python、C# 和 C++,当他不在 Iron Software 利用这些技能时,他就在游戏编程。分享产品测试、产品开发和研究的责任,Jordi 在持续的产品改进中增加了巨大的价值。多样的经验使他面临挑战并保持投入,他表示这是在 Iron Software 工作的最喜欢的方面之一。Jordi 在佛罗里达州迈阿密长大,并在佛罗里达大学学习计算机科学和统计学。