当前位置: 首页 > news >正文

借助Aspose.BarCode条码控件,C# 中的文本转 QR 码生成器

二维码用于在较小的空间内存储大量数据。它们易于使用,可以通过智能手机或其他设备扫描来打开网站、观看视频或访问其他编码信息。在这篇博文中,我们将学习如何使用 C# 以编程方式生成基于文本的 QR 码。我们将提供分步指南和代码片段,帮助您使用 C# 开发自己的文本到 QR 码生成器。

Aspose.BarCode for .NET 是一个功能强大的API,可以从任意角度生成和识别多种图像类型的一维和二维条形码。开发人员可以轻松添加条形码生成和识别功能,以及在.NET应用程序中将生成的条形码导出为高质量的图像格式。 Aspose API支持流行文件格式处理,并允许将各类文档导出或转换为固定布局文件格式和最常用的图像/多媒体格式。

Aspose.BarCode 最新下载icon-default.png?t=N7T8https://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 码

我们可以按照以下步骤轻松地从任何提供的文本生成二维码:

  1. 创建BarcodeGenerator类的实例。
  2. EncodeTypes设置为QR
  3. 指定要编码的输入文本。
  4. (可选)指定 QR 码自定义选项。
  5. 最后,调用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# 中的文本转二维码

在 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 代码的生成

用 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");

用 C# 生成带文本的 QR 码

您可以使用使用此 API 开发的在线QR 代码生成器 Web 应用程序,从在线输入的任何文本免费生成 QR 代码。

在这篇博文中,我们学习了如何使用 C# 开发文本到 QR 码生成器。我们还了解了如何自定义 QR 码并向生成的图像添加标题。

http://www.lryc.cn/news/301960.html

相关文章:

  • vue打包优化,webpack的8大配置方案
  • B端系统从0到1:有几步,其中需求分析要做啥?
  • django中查询优化
  • 【JavaScript】输入输出语法
  • 多模态基础--- word Embedding
  • Mysql 日志
  • 【开源】SpringBoot框架开发服装店库存管理系统
  • 云原生之容器编排实践-在K8S集群中使用Registry2搭建私有镜像仓库
  • 标准IO 2月4日学习笔记
  • 如何在1Panel上偷渡HTTP/3
  • Qt实用技巧:QCustomPlot做北斗GPS显示绝对位置运动轨迹和相对位置运动轨迹图的时,使图按照输入点顺序连曲线
  • 116 C++ 可变参数函数,initializer_list (初始化列表), 省略号形参
  • 强国有我社会实践公益活动在合肥市庐阳区开展
  • Nginx 正向代理、反向代理
  • 软考学习--计算机组成原理与体系结构
  • fish终端下conda activate失败
  • FPGA之移位寄存器
  • Android Compose Material3 ModalNavigationDrawer 抽屉的使用(处理了一些坑)
  • golang select两个channel性能稳定,三个channel时性能会发生抖动,为什么?
  • VSCODE上使用python_Django
  • 探索IDE的世界:什么是IDE?以及适合新手的IDE推荐
  • DoRA(权重分解低秩适应):一种新颖的模型微调方法
  • centos7.9 搭建k8s
  • 使用vite创建项目
  • EXTI外部中断
  • 小肥柴慢慢手写数据结构(C篇)(5-4 中场小结)
  • flutter 功能
  • Sql Server 存储过程
  • 二.重新回炉Spring Framework:Spring Framework主要组件概览
  • Open CASCADE学习|曲线向曲面投影