广西建设职业技术学院贫困生网站,站长之家字体,创建网站时可使用的数据库有,tv域名的网站二维码用于在较小的空间内存储大量数据。它们易于使用#xff0c;可以通过智能手机或其他设备扫描来打开网站、观看视频或访问其他编码信息。在这篇博文中#xff0c;我们将学习如何使用 C# 以编程方式生成基于文本的 QR 码。我们将提供分步指南和代码片段#xff0c;帮助您…二维码用于在较小的空间内存储大量数据。它们易于使用可以通过智能手机或其他设备扫描来打开网站、观看视频或访问其他编码信息。在这篇博文中我们将学习如何使用 C# 以编程方式生成基于文本的 QR 码。我们将提供分步指南和代码片段帮助您使用 C# 开发自己的文本到 QR 码生成器。
Aspose.BarCode for .NET 是一个功能强大的API可以从任意角度生成和识别多种图像类型的一维和二维条形码。开发人员可以轻松添加条形码生成和识别功能以及在.NET应用程序中将生成的条形码导出为高质量的图像格式。 Aspose API支持流行文件格式处理并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。
Aspose.BarCode 最新下载https://www.evget.com/product/576/download
C# 文本到 QR 码生成器 API
为了将任何文本转换为 QR 码我们将使用Aspose.BarCode for .NET API。它允许在 .NET 应用程序中生成、扫描和读取条形码和 QR 码。该 API 允许开发人员轻松地将生成的条形码或 QR 码保存为各种图像格式例如PNG、JPEG和TIFF。它支持 60 多种条形码符号例如 QR 码、Code 128、Code 39、EAN、UPC 等。
请下载API的DLL或使用以下NuGet命令安装它 PM Install-Package Aspose.BarCode在 C# 中将文本转换为 QR 码
我们可以按照以下步骤轻松地从任何提供的文本生成二维码
创建BarcodeGenerator类的实例。将EncodeTypes设置为QR。指定要编码的输入文本。可选指定 QR 码自定义选项。最后调用Save()方法将生成的二维码图像保存到给定的文件路径中。
以下代码示例展示了如何使用 C# 将文本转换为二维码。 // This code example demonstartes how to generate a QR code from Text.
// Initialize the BarcodeGenerator
// Specify Encode type as QR
var generator new BarcodeGenerator(EncodeTypes.QR);// Specify code text to encode
generator.CodeText Your text goes here!;// Specify the size of the image
generator.Parameters.Barcode.XDimension.Pixels 8;
generator.Parameters.Resolution 500;// Save the generated QR code
generator.Save(C:\\Files\\Text_QR_Code.jpg);在 C# 中自定义文本到 QR 代码的生成
我们可以按照前面提到的步骤自定义从文本生成的二维码的外观。然而我们需要设置一些额外的属性来自定义背景颜色、边框颜色、图像高度等。
以下代码示例展示了如何在 C# 中自定义文本以生成 QR 码。 // This code example demonstartes how to generate a QR code from Text.
// Initialize the BarcodeGenerator
// Specify Encode type as QR
var generator new BarcodeGenerator(EncodeTypes.QR);// Specify code text to encode
generator.CodeText Your text goes here!;// Specify the size of the image
generator.Parameters.Barcode.XDimension.Pixels 8;// Set background color
generator.Parameters.BackColor Color.Red;// Set QR color
generator.Parameters.Barcode.BarColor Color.Blue;// Set image resolution
generator.Parameters.Resolution 300;// Set border
generator.Parameters.Border.DashStyle BorderDashStyle.Solid;
generator.Parameters.Border.Color Color.Yellow;
generator.Parameters.Border.Visible true;
generator.Parameters.Border.Width.Point 4;// Save the generated QR code
generator.Save(C:\\Files\\Customized_QR_Code.jpg);用 C# 生成带文本的 QR 码
我们还可以将人类可读的文本添加到生成的二维码图像中。它可以是主文本标签、顶部标题或底部标题。我们可以按照前面提到的步骤添加代码文本和下面的标题。但是我们只需要设置CodeTextParameters 和 CaptionBelow 属性如下所示 // This code example demonstartes how to generate a QR code from Text.
// Initialize the BarcodeGenerator
// Specify Encode type as QR
var generator new BarcodeGenerator(EncodeTypes.QR);// Specify code text to encode
generator.CodeText Your text goes here!;// Specify the size of the image
generator.Parameters.Barcode.XDimension.Pixels 8;// Set background color
generator.Parameters.BackColor Color.White;// Set QR color
generator.Parameters.Barcode.BarColor Color.Blue;// Set image resolution
generator.Parameters.Resolution 300;// Set border
generator.Parameters.Border.DashStyle BorderDashStyle.Solid;
generator.Parameters.Border.Color Color.Red;
generator.Parameters.Border.Visible true;
generator.Parameters.Border.Width.Point 4;// Show the code text above the QR code
generator.Parameters.Barcode.CodeTextParameters.TwoDDisplayText Aspose.BarCode;
generator.Parameters.Barcode.CodeTextParameters.Location CodeLocation.Above;// Set the caption below the QR code
generator.Parameters.Barcode.CodeTextParameters.TwoDDisplayText HELLO;
generator.Parameters.CaptionBelow.Text ASPOSE;
generator.Parameters.CaptionBelow.Visible true;
generator.Parameters.CaptionBelow.Font.Style FontStyle.Bold;
generator.Parameters.CaptionBelow.Font.Size.Pixels 18;
generator.Parameters.CaptionBelow.Font.FamilyName Verdana;// Save the generated QR code
generator.Save(C:\\Files\\QR_Code_with_text.jpg);您可以使用使用此 API 开发的在线QR 代码生成器 Web 应用程序从在线输入的任何文本免费生成 QR 代码。
在这篇博文中我们学习了如何使用 C# 开发文本到 QR 码生成器。我们还了解了如何自定义 QR 码并向生成的图像添加标题。