在实际环境中测试
在生产中测试无水印。
随时随地为您服务。
欢迎阅读我们的创建指南 QR 码 使用 C#! QR 代码和 .NET 条形码 DLL 已成为快速有效地共享信息的流行方式。无论您是在开发应用程序、管理网站,还是在寻找一种简便的链接共享方式,这些代码都会非常有用。在本指南中,我们将演示如何使用 IronQR确保您可以根据自己的需要生成 QR 代码。该库使任何使用 C# 的人都能轻松创建 QR 代码,而无需进入复杂的逻辑。我们将指导您完成整个步骤,确保您拥有开始使用所需的一切。无论您是想为自己的应用程序添加 QR 代码生成器功能,还是只是想了解它是如何实现的,您都找对了地方。让我们开始吧
1.在 Visual Studio 中创建 Windows 窗体应用程序
2.使用 NuGet 安装 QR 库
3.设计表单前端元素
4.编写 QR 生成逻辑5.运行应用程序并开始创建二维码
IronQR IronQR 是一个 C# QR 码库,用于将 QR 码功能集成到 .NET 应用程序中。IronQR 支持多种 .NET 版本和项目类型,包括 C#、VB.NET、F#、.NET Core、.NET Standard、.NET Framework 等,确保与 Windows、Linux、macOS、iOS 和 Android 等各种开发环境兼容。
IronQR 与众不同之处在于其先进的功能,包括以下能力 读取二维码 和 生成二维码支持多种图像格式,以及调整大小、样式和在 QR 代码中添加徽标等自定义选项。
除了基本的 QR 代码生成功能外,IronQR 还提供了多项功能,可满足各种 QR 代码相关任务的需要。让我们来了解一下这些功能,并查看它们的示例代码,您可以将这些代码集成到任何类型的 .NET 应用程序模板(如控制台应用程序)中。
IronQR 擅长解码 QR 代码,为用户提供了获取 QR 代码中嵌入信息的直接方法。您可以快速、准确地从 QR 码中提取数据,从简单的 URL 到复杂的嵌入信息。
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
IronQr.License.LicenseKey = "License-Key";
// Load the image file that contains the QR Code
var inputImage = AnyBitmap.FromFile("QRCode.png");
// Prepare the image for QR code detection
QrImageInput qrInput = new QrImageInput(inputImage);
// Initialize the QR Code reader
QrReader qrReader = new QrReader();
// Execute QR Code reading on the provided image
IEnumerable<QrResult> qrResults = qrReader.Read(qrInput);
// Assuming you have the QR results in qrResults as before
foreach (var result in qrResults)
{
Console.WriteLine(result.Value); // Print the QR code content to the console
}
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
IronQr.License.LicenseKey = "License-Key";
// Load the image file that contains the QR Code
var inputImage = AnyBitmap.FromFile("QRCode.png");
// Prepare the image for QR code detection
QrImageInput qrInput = new QrImageInput(inputImage);
// Initialize the QR Code reader
QrReader qrReader = new QrReader();
// Execute QR Code reading on the provided image
IEnumerable<QrResult> qrResults = qrReader.Read(qrInput);
// Assuming you have the QR results in qrResults as before
foreach (var result in qrResults)
{
Console.WriteLine(result.Value); // Print the QR code content to the console
}
IRON VB CONVERTER ERROR developers@ironsoftware.com
我们使用以下 QR 进行扫描:
输出结果是这样的
该过程首先要纳入必要的命名空间,即 "IronQr "和 "IronSoftware.Drawing",并特别提及 "IronSoftware.Drawing "命名空间中的 "Color",以处理图像处理。
在开始读取 QR 码之前,必须先将许可证密钥分配给 IronQr.License.LicenseKey
,以此激活软件。然后,代码会使用 AnyBitmap.FromFile
从文件加载二维码图像。("QRCode.png")`.
图像加载完成后,下一步就是为二维码检测做准备。准备工作是通过创建一个 QrImageInput
对象来完成的,该对象是图像的容器。
该功能的核心在于 "QrReader "类,它被实例化并用于执行二维码读取操作。阅读器会分析准备好的图片 qrInput
,搜索其中包含的任何 QR 代码。该操作的结果是一个 QrResult
对象集合,每个对象代表图像中检测到的 QR 代码。
为了访问和利用 QR 代码中编码的数据,代码使用一个 foreach 循环遍历结果集合。每个 "QrResult "对象都包含可访问和显示的属性,如二维码的值。
IronQR 为您提供了从图像中读取 QR 码的不同方式,使其能满足各种需求。其中一个选项是混合扫描模式,它兼顾了速度和准确性,在二维码不清晰或部分隐藏时非常有用。
另一种是机器学习 (ML) 扫描模式,使用智能技术读取损坏或不易正常读取的 QR 码。该模式非常适合 QR 码难以检测的恶劣环境。
最后是基本扫描模式,它是扫描清晰明了的二维码最快最简单的方法。在您需要快速获得结果且二维码易于读取时,使用该模式最为合适。
using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
IronQr.License.LicenseKey = "License-Key";
// Load the image file that contains the QR Code
var inputImage = AnyBitmap.FromFile("QRCode.png");
QrImageInput mixedScanInput = new QrImageInput(inputImage, QrScanMode.OnlyDetectionModel);
IEnumerable<QrResult> mixedScanResults = new QrReader().Read(mixedScanInput);
QrImageInput mlScanInput = new QrImageInput(inputImage, QrScanMode.OnlyDetectionModel);
IEnumerable<QrResult> mlScanResults = new QrReader().Read(mlScanInput);
QrImageInput basicScanInput = new QrImageInput(inputImage, QrScanMode.OnlyBasicScan);
IEnumerable<QrResult> basicScanResults = new QrReader().Read(basicScanInput);
using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
IronQr.License.LicenseKey = "License-Key";
// Load the image file that contains the QR Code
var inputImage = AnyBitmap.FromFile("QRCode.png");
QrImageInput mixedScanInput = new QrImageInput(inputImage, QrScanMode.OnlyDetectionModel);
IEnumerable<QrResult> mixedScanResults = new QrReader().Read(mixedScanInput);
QrImageInput mlScanInput = new QrImageInput(inputImage, QrScanMode.OnlyDetectionModel);
IEnumerable<QrResult> mlScanResults = new QrReader().Read(mlScanInput);
QrImageInput basicScanInput = new QrImageInput(inputImage, QrScanMode.OnlyBasicScan);
IEnumerable<QrResult> basicScanResults = new QrReader().Read(basicScanInput);
Imports IronQr
Imports IronQr.Enum
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
IronQr.License.LicenseKey = "License-Key"
' Load the image file that contains the QR Code
Dim inputImage = AnyBitmap.FromFile("QRCode.png")
Dim mixedScanInput As New QrImageInput(inputImage, QrScanMode.OnlyDetectionModel)
Dim mixedScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(mixedScanInput)
Dim mlScanInput As New QrImageInput(inputImage, QrScanMode.OnlyDetectionModel)
Dim mlScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(mlScanInput)
Dim basicScanInput As New QrImageInput(inputImage, QrScanMode.OnlyBasicScan)
Dim basicScanResults As IEnumerable(Of QrResult) = (New QrReader()).Read(basicScanInput)
IronQR 的高级 QR 码读取功能旨在为 QR 码扫描和解码提供全面而细致的方法。这套功能超越了基本的 QR 码读取功能,提供了更深层次的互动和数据提取。
using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
IronQr.License.LicenseKey = "License-Key";
var imageToScan = AnyBitmap.FromFile("QRCode.png");
QrImageInput qrInput = new QrImageInput(imageToScan);
QrReader qrScanner = new QrReader();
IEnumerable<QrResult> scanResults = qrScanner.Read(qrInput);
foreach (QrResult qrResult in scanResults)
{
Console.WriteLine(qrResult.Value);
Console.WriteLine(qrResult.Url);
foreach (IronSoftware.Drawing.PointF coordinate in qrResult.Points)
{
Console.WriteLine($"{coordinate.X}, {coordinate.Y}");
}
}
using IronQr;
using IronQr.Enum;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
IronQr.License.LicenseKey = "License-Key";
var imageToScan = AnyBitmap.FromFile("QRCode.png");
QrImageInput qrInput = new QrImageInput(imageToScan);
QrReader qrScanner = new QrReader();
IEnumerable<QrResult> scanResults = qrScanner.Read(qrInput);
foreach (QrResult qrResult in scanResults)
{
Console.WriteLine(qrResult.Value);
Console.WriteLine(qrResult.Url);
foreach (IronSoftware.Drawing.PointF coordinate in qrResult.Points)
{
Console.WriteLine($"{coordinate.X}, {coordinate.Y}");
}
}
Imports IronQr
Imports IronQr.Enum
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
IronQr.License.LicenseKey = "License-Key"
Dim imageToScan = AnyBitmap.FromFile("QRCode.png")
Dim qrInput As New QrImageInput(imageToScan)
Dim qrScanner As New QrReader()
Dim scanResults As IEnumerable(Of QrResult) = qrScanner.Read(qrInput)
For Each qrResult As QrResult In scanResults
Console.WriteLine(qrResult.Value)
Console.WriteLine(qrResult.Url)
For Each coordinate As IronSoftware.Drawing.PointF In qrResult.Points
Console.WriteLine($"{coordinate.X}, {coordinate.Y}")
Next coordinate
Next qrResult
这是我们使用 IronQR 扫描二维码时的输出结果:
我们使用以下二维码:
每个 QrResult
对象都提供对解码数据的访问权限 (值),任何嵌入的 URL (Url
)和空间坐标 (点数) 图像中的 QR 码。
对于检测到的每个 QR 码,IronQR 都会提供详细信息,包括 QR 码中包含的确切内容和任何 URL。此外,该库还提供 QR 码在图像中边角的精确坐标 (点 "属性).
要在 C# 应用程序中使用 IronQR QR 代码库创建 QR 代码生成器,请仔细按照以下步骤操作。本指南将带您设置 Windows 窗体应用程序、安装 IronQR 库、编写生成二维码的代码并了解输出结果。
选择Windows 窗体应用程序作为项目类型。确保选择 C# 作为语言。
输入项目名称并选择保存位置。然后在下一个屏幕上选择 .NET framework。然后点击创建。
它将在 Visual Studio 中创建并打开一个 Windows 窗体应用程序。
现在是在项目中安装 IronQR 库的时候了。你可以通过不同的方法安装 IronQR 库。请根据自己的喜好选择一种:
在搜索框中键入 IronQR 并按 Enter 键。
在列表中找到 IronQR,点击旁边的 安装。
启动 QR 代码生成器应用程序后,用户会立即看到一个醒目的标题,标题为 "QR Generator IronQR",字体粗体,极具权威性。之所以选用 Agency FB 字体,是因为该字体线条简洁、现代,给人一种高效、精确的感觉。标题字体大小为 48 点,既突出又醒目,既能吸引用户的注意力,又能牢固树立应用程序的形象。
输入部分的核心是一个简单而基本的组件:文本输入框。在这里,用户可以输入他们希望编码到二维码中的数据。输入框非常宽敞,可容纳大量文本,并位于顶部附近的显著位置。
在文本输入下方,"选择徽标 "区域允许进行额外的定制。用户可以上传嵌入二维码的徽标,以提高品牌识别度或个性化二维码。相邻的图片框可预览所选徽标,提供即时的视觉反馈。
向右移动,界面会显示颜色选择选项。用户可以通过两个按钮,一个是二维码颜色按钮,另一个是背景颜色按钮,自定义二维码的调色板。这些按钮旁边的丰富文本框显示了当前选择的颜色。
输入部分的文字、徽标和颜色选项布局考虑周到,体现了用户在创建二维码时对优先事项的清晰理解。它将功能性与灵活性相结合,既能让用户快速高效地输入必要信息,又能提供发挥创意的空间。
在颜色定制工具旁边,用户可以找到 "尺寸 "输入。这个数字设置非常重要,因为它决定了二维码的整体尺寸,确保二维码在预定的显示环境中(无论是名片、传单还是数字屏幕)完美匹配。
在尺寸输入旁边,"边距 "字段允许用户指定二维码周围的空白区域。边距不仅是一种美学选择,也是一种功能元素,会影响扫描仪对二维码的可读性。应用程序提供了一个上下数字控件,方便用户调整这一参数。
一旦用户开始生成 QR 码,表单左侧标有 "输出 "的大图片框就会成为焦点。它是一个动态显示屏,可实时预览生成的 QR 代码。这种即时的视觉反馈对于用户在保存之前验证他们的设计选择并确保 QR 代码符合他们的期望至关重要。
生成 QR "按钮是应用程序界面中的一个关键控制元素。该按钮位于表单的重要位置,是 QR 代码创建过程的催化剂。点击该按钮后,应用程序将接收用户定义的所有输入数据和样式参数,并开始生成自定义 QR 代码。
生成 QR 代码并显示在输出预览区后,"保存 QR "按钮就会发挥作用。点击后,会打开一个保存对话框,允许用户选择所需的文件格式和保存位置。
只需单击一下,该按钮即可清除所有先前的输入和选择,将所有设置恢复为默认值。这是表单的一个重要方面,提供了一种无需手动调整每个选项即可重新初始化应用程序的快速方法。
首先,应用程序需要包含必要的命名空间:"IronQr "和 "IronSoftware.Drawing"。这些命名空间至关重要,因为它们提供了在应用程序中生成和处理 QR 代码和颜色所需的功能。自定义的 "Color "类是为方便二维码生成中的颜色管理而定义的,它覆盖了默认的 "System.Drawing.Color",以确保与 IronQR 的要求兼容。
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
QR_Generator` 类的构造函数在准备应用程序的使用中起着至关重要的作用。在这里,应用程序的组件被初始化,这是 Windows 窗体应用程序中设置窗体 UI 元素的标准步骤。
public QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}
public QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}
'INSTANT VB WARNING: The following constructor is declared outside of its associated class:
'ORIGINAL LINE: public QR_Generator()
Public Sub New()
InitializeComponent()
SetLicenseKey()
EnsureDirectoryExists(qrCodesDirectory)
End Sub
SetLicenseKey`:调用此方法可为 IronQR 库应用有效的许可证密钥。商业应用程序必须使用许可证密钥,才能解锁 IronQR 库的全部功能。
EnsureDirectoryExists"(确保目录存在):鉴于需要保存生成的 QR 代码,此方法可确保有专门的可用目录。它会检查应用程序启动路径中是否存在 "QR 码 "目录,如果不存在,则创建该目录。
为确保 IronQR 不受任何限制地运行,必须使用有效的许可证密钥。这是一个静态方法,旨在使用已购买或试用的许可证密钥配置库。下面的代码片段说明了如何设置许可证密钥:
private static void SetLicenseKey()
{
IronQr.License.LicenseKey = "YOUR_LICENSE_KEY";
}
private static void SetLicenseKey()
{
IronQr.License.LicenseKey = "YOUR_LICENSE_KEY";
}
Private Shared Sub SetLicenseKey()
IronQr.License.LicenseKey = "YOUR_LICENSE_KEY"
End Sub
将 "YOUR\_LICENSE\_KEY"
替换为从 Iron Software 获取的实际许可证密钥。该方法在 "QR_Generator "类的构造函数中调用,确保应用程序启动后,在生成任何 QR 代码之前,立即应用许可证。
应用程序使用 EnsureDirectoryExists
方法检查用于存储二维码的指定目录是否存在。如果不存在,则创建目录。该方法需要一个 string
参数,即要检查或创建的目录的路径。下面是该方法的实现过程:
private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}
private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}
Private Shared Sub EnsureDirectoryExists(ByVal path As String)
If Not System.IO.Directory.Exists(path) Then
System.IO.Directory.CreateDirectory(path)
End If
End Sub
该方法利用 System.IO
命名空间与文件系统交互。它首先使用 Directory.Exists
检查指定路径下的目录是否存在。如果目录不存在 (返回 false)然后使用
Directory.CreateDirectory` 创建目录。
QR 代码目录的路径在 "QR_Generator "类构造函数中定义为 "qrCodesDirectory",它结合了应用程序的启动路径和 "QR 代码 "文件夹名称:
string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");
string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");
Dim qrCodesDirectory As String = System.IO.Path.Combine(Application.StartupPath, "QR Codes")
应用程序在用户界面上提供了两个按钮,每个按钮都与选择颜色的方法相关联:btn\_color\_Click
用于二维码颜色,btn\_background\_Click
用于背景颜色。这些方法利用颜色对话框让用户选择颜色。
使用颜色对话框选择颜色后,所选颜色将转换为十六进制字符串格式。这是必要的,因为 IronQR 库要求以十六进制格式指定颜色。转换是通过 ColorToHex
方法完成的:
private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
Private Function ColorToHex(ByVal color As System.Drawing.Color) As String
Return $"#{color.R:X2}{color.G:X2}{color.B:X2}"
End Function
UpdateColor "方法获取所选颜色,并使用十六进制字符串将其转换为 IronSoftware.Drawing.Color 格式,然后根据所选颜色更新二维码的前景色或背景色。它还会更新用户界面,以反映新的颜色选择:
private void UpdateColor(ref Color targetColor, Control display, bool isBackground)
{
if (select_color.ShowDialog() == DialogResult.OK)
{
var hexColor = ColorToHex(select_color.Color);
targetColor = new Color(hexColor);
display.BackColor = select_color.Color;
}
}
private void UpdateColor(ref Color targetColor, Control display, bool isBackground)
{
if (select_color.ShowDialog() == DialogResult.OK)
{
var hexColor = ColorToHex(select_color.Color);
targetColor = new Color(hexColor);
display.BackColor = select_color.Color;
}
}
Private Sub UpdateColor(ByRef targetColor As Color, ByVal display As Control, ByVal isBackground As Boolean)
If select_color.ShowDialog() = DialogResult.OK Then
Dim hexColor = ColorToHex(select_color.Color)
targetColor = New Color(hexColor)
display.BackColor = select_color.Color
End If
End Sub
应用程序包含一个按钮 (点击) 点击后会打开一个文件对话框,允许用户选择一个图像文件作为徽标。这一功能对于希望将二维码品牌化的企业或个人来说至关重要。以下是徽标选择和整合过程的处理方式:
private void btn_logo_Click(object sender, EventArgs e)
{
if (select_logo.ShowDialog() == DialogResult.OK)
{
try
{
logoBmp = new AnyBitmap(select_logo.FileName);
selected_logo.Image = Image.FromFile(select_logo.FileName);
}
catch (Exception ex)
{
ShowError("An error occurred while loading the logo", ex.Message);
}
}
}
private void btn_logo_Click(object sender, EventArgs e)
{
if (select_logo.ShowDialog() == DialogResult.OK)
{
try
{
logoBmp = new AnyBitmap(select_logo.FileName);
selected_logo.Image = Image.FromFile(select_logo.FileName);
}
catch (Exception ex)
{
ShowError("An error occurred while loading the logo", ex.Message);
}
}
}
Private Sub btn_logo_Click(ByVal sender As Object, ByVal e As EventArgs)
If select_logo.ShowDialog() = DialogResult.OK Then
Try
logoBmp = New AnyBitmap(select_logo.FileName)
selected_logo.Image = Image.FromFile(select_logo.FileName)
Catch ex As Exception
ShowError("An error occurred while loading the logo", ex.Message)
End Try
End If
End Sub
成功选择图像后,应用程序会尝试加载图像并显示预览。然后,"AnyBitmap "对象 "logoBmp "将被设置为所选图像,QR 生成逻辑随后将使用该图像。
生成过程始于用户点击 "生成 "按钮,该按钮与 btn\_generate\_Click
方法相连。该方法充当触发器,调用实际生成逻辑所在的 GenerateQRCode
函数。
private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}
private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}
Private Sub btn_generate_Click(ByVal sender As Object, ByVal e As EventArgs)
GenerateQRCode()
End Sub
在 "GenerateQRCode "方法中,应用程序根据指定的参数(包括输入文本和样式选项)构建 QR 码。该方法封装了 QR 代码的创建过程,应用了选定的颜色、尺寸、边距和可选的徽标。
private void GenerateQRCode()
{
try
{
var options = new QrOptions(QrErrorCorrectionLevel.High);
var myQr = QrWriter.Write(txt_QR.Text, options);
var style = CreateStyleOptions();
var qrImage = myQr.Save(style);
var fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png";
var fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName);
qrImage.SaveAs(fullPath);
pictureBox.Image = Image.FromFile(fullPath);
}
catch (Exception ex)
{
ShowError("An error occurred during QR code generation or saving", ex.Message);
}
}
private void GenerateQRCode()
{
try
{
var options = new QrOptions(QrErrorCorrectionLevel.High);
var myQr = QrWriter.Write(txt_QR.Text, options);
var style = CreateStyleOptions();
var qrImage = myQr.Save(style);
var fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png";
var fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName);
qrImage.SaveAs(fullPath);
pictureBox.Image = Image.FromFile(fullPath);
}
catch (Exception ex)
{
ShowError("An error occurred during QR code generation or saving", ex.Message);
}
}
Private Sub GenerateQRCode()
Try
Dim options = New QrOptions(QrErrorCorrectionLevel.High)
Dim myQr = QrWriter.Write(txt_QR.Text, options)
Dim style = CreateStyleOptions()
Dim qrImage = myQr.Save(style)
Dim fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png"
Dim fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName)
qrImage.SaveAs(fullPath)
pictureBox.Image = Image.FromFile(fullPath)
Catch ex As Exception
ShowError("An error occurred during QR code generation or saving", ex.Message)
End Try
End Sub
QrOptions" 对象可定义纠错级别,从而增强二维码对损坏或模糊的抵御能力。CreateStyleOptions "方法会生成一个 "QrStyleOptions "对象,其中包括用户的自定义设置,如颜色、尺寸和徽标。下面是该方法的详细信息:
private QrStyleOptions CreateStyleOptions()
{
return new QrStyleOptions
{
BackgroundColor = bgColor,
Color = color,
Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"),
Margins = Convert.ToInt32(txt_margin.Value),
Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null
};
}
private QrStyleOptions CreateStyleOptions()
{
return new QrStyleOptions
{
BackgroundColor = bgColor,
Color = color,
Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"),
Margins = Convert.ToInt32(txt_margin.Value),
Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null
};
}
Private Function CreateStyleOptions() As QrStyleOptions
'INSTANT VB TODO TASK: Throw expressions are not converted by Instant VB:
'ORIGINAL LINE: return new QrStyleOptions { BackgroundColor = bgColor, Color = color, Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"), Margins = Convert.ToInt32(txt_margin.Value), Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null };
Return New QrStyleOptions With {
.BackgroundColor = bgColor,
.Color = color,
.Dimensions = If(txt_dimension.Value > 0, Convert.ToInt32(txt_dimension.Value), throw New ArgumentException("Please select valid dimensions!")),
.Margins = Convert.ToInt32(txt_margin.Value),
.Logo = If(logoBmp IsNot Nothing, New QrLogo With {
.Bitmap = logoBmp,
.Width = 50,
.Height = 50,
.CornerRadius = 5
}, Nothing)
}
End Function
该方法会创建一个 QrStyleOptions
对象,然后二维码生成逻辑会使用该对象来应用用户的首选项。选项包括
BackgroundColor
和Color
:这些属性可设置二维码的背景和前景颜色,从而实现与品牌或审美偏好相匹配的个性化外观。Logo
:如果用户选择包含徽标,则可在此配置徽标的具体尺寸和边角半径,使其看起来更精致。保存功能由 "保存 "按钮触发,该按钮与 btn\_save\_Click
方法相连。该方法调用 "SaveQRCode",实现保存逻辑。该过程包括显示保存文件对话框,允许用户选择保存二维码的文件格式和位置。
private void btn_save_Click(object sender, EventArgs e)
{
SaveQRCode();
}
private void SaveQRCode()
{
if (pictureBox.Image == null)
{
MessageBox.Show("There is no QR code to save.", "Error");
return;
}
saveFileDialog.Filter = "PNG Files
*.png
JPEG Files
*.jpg";
saveFileDialog.Title = "Save QR Code";
saveFileDialog.FileName = "QRCode";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName));
MessageBox.Show("QR Code has been saved!", "Success");
}
catch (Exception ex)
{
ShowError("An error occurred while saving the QR code", ex.Message);
}
}
}
private void btn_save_Click(object sender, EventArgs e)
{
SaveQRCode();
}
private void SaveQRCode()
{
if (pictureBox.Image == null)
{
MessageBox.Show("There is no QR code to save.", "Error");
return;
}
saveFileDialog.Filter = "PNG Files
*.png
JPEG Files
*.jpg";
saveFileDialog.Title = "Save QR Code";
saveFileDialog.FileName = "QRCode";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName));
MessageBox.Show("QR Code has been saved!", "Success");
}
catch (Exception ex)
{
ShowError("An error occurred while saving the QR code", ex.Message);
}
}
}
Private Sub btn_save_Click(ByVal sender As Object, ByVal e As EventArgs)
SaveQRCode()
End Sub
Private Sub SaveQRCode()
If pictureBox.Image Is Nothing Then
MessageBox.Show("There is no QR code to save.", "Error")
Return
End If
saveFileDialog.Filter = "PNG Files *.png JPEG Files *.jpg"
saveFileDialog.Title = "Save QR Code"
saveFileDialog.FileName = "QRCode"
If saveFileDialog.ShowDialog() = DialogResult.OK Then
Try
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName))
MessageBox.Show("QR Code has been saved!", "Success")
Catch ex As Exception
ShowError("An error occurred while saving the QR code", ex.Message)
End Try
End If
End Sub
此方法会检查是否有生成的 QR 代码。如果有,它会向用户提供以 PNG 或 JPEG 格式保存文件的选项。DetermineImageFormat "函数确保根据用户选择的文件扩展名以正确的格式保存图像。
private System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath)
{
return System.IO.Path.GetExtension(filePath).ToLower() == ".jpg" ? System.Drawing.Imaging.ImageFormat.Jpeg : System.Drawing.Imaging.ImageFormat.Png;
}
private System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath)
{
return System.IO.Path.GetExtension(filePath).ToLower() == ".jpg" ? System.Drawing.Imaging.ImageFormat.Jpeg : System.Drawing.Imaging.ImageFormat.Png;
}
Private Function DetermineImageFormat(ByVal filePath As String) As System.Drawing.Imaging.ImageFormat
Return If(System.IO.Path.GetExtension(filePath).ToLower() = ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg, System.Drawing.Imaging.ImageFormat.Png)
End Function
这种灵活性使用户可以选择最适合其需求的格式,无论其优先考虑的是质量还是性能。 (巴新) 或文件大小 (JPEG).
重置功能与 "Reset "按钮相连,该按钮调用 btn\_reset\_Click
方法。该方法反过来又会调用 ResetFields
,该函数旨在清除所有用户输入并恢复所有设置的默认值,包括文本字段、颜色选择和所选徽标。
private void btn_reset_Click(object sender, EventArgs e)
{
ResetFields();
}
private void ResetFields()
{
txt_QR.Text = string.Empty;
txt_dimension.Value = 200;
txt_margin.Value = 0;
bgColor = Color.White;
color = Color.Black;
txt_selected_color.BackColor = System.Drawing.Color.White;
txt_selected_bgcolor.BackColor = System.Drawing.Color.Black;
logoBmp = null;
selected_logo.Image = null;
pictureBox.Image = null;
}
private void btn_reset_Click(object sender, EventArgs e)
{
ResetFields();
}
private void ResetFields()
{
txt_QR.Text = string.Empty;
txt_dimension.Value = 200;
txt_margin.Value = 0;
bgColor = Color.White;
color = Color.Black;
txt_selected_color.BackColor = System.Drawing.Color.White;
txt_selected_bgcolor.BackColor = System.Drawing.Color.Black;
logoBmp = null;
selected_logo.Image = null;
pictureBox.Image = null;
}
Private Sub btn_reset_Click(ByVal sender As Object, ByVal e As EventArgs)
ResetFields()
End Sub
Private Sub ResetFields()
txt_QR.Text = String.Empty
txt_dimension.Value = 200
txt_margin.Value = 0
bgColor = Color.White
color = Color.Black
txt_selected_color.BackColor = System.Drawing.Color.White
txt_selected_bgcolor.BackColor = System.Drawing.Color.Black
logoBmp = Nothing
selected_logo.Image = Nothing
pictureBox.Image = Nothing
End Sub
此方法可重置 QR 代码生成过程中涉及的每个组件。例如,它会清除二维码文本,将尺寸和边距设置为默认值,并删除任何选定的颜色或徽标。
应用程序使用 ShowError
方法以用户友好的方式显示错误信息。该方法需要两个参数:标题和信息,这两个参数为用户提供了有关错误的上下文。下面是该方法的实现过程:
private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}
private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}
Private Shared Sub ShowError(ByVal title As String, ByVal message As String)
MessageBox.Show($"{title}: {message}", "Error")
End Sub
该方法适用于应用程序的不同部分,以确保在发生错误时,能以简洁明了的信息及时通知用户。例如,如果在加载徽标或生成二维码的过程中发生错误,应用程序会调用 "ShowError "来显示有关问题的详细信息。
下面是完整的代码,可以帮助您更容易地理解代码:
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
namespace IronQR_QR_Generator_WinForms
{
public partial class QR_Generator : Form
{
string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");
Color bgColor = Color.White;
Color color = Color.Black;
AnyBitmap? logoBmp = null;
public QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}
private static void SetLicenseKey()
{
IronQr.License.LicenseKey = "License-Key";
}
private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}
private void btn_color_Click(object sender, EventArgs e)
{
UpdateColor(ref color, txt_selected_color, false);
}
private void btn_background_Click(object sender, EventArgs e)
{
UpdateColor(ref bgColor, txt_selected_bgcolor, true);
}
private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
private void UpdateColor(ref Color targetColor, Control display, bool isBackground)
{
if (select_color.ShowDialog() == DialogResult.OK)
{
var hexColor = ColorToHex(select_color.Color);
targetColor = new Color(hexColor);
display.BackColor = select_color.Color;
}
}
private void btn_logo_Click(object sender, EventArgs e)
{
if (select_logo.ShowDialog() == DialogResult.OK)
{
try
{
logoBmp = new AnyBitmap(select_logo.FileName);
selected_logo.Image = Image.FromFile(select_logo.FileName);
}
catch (Exception ex)
{
ShowError("An error occurred while loading the logo", ex.Message);
}
}
}
private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}
private void GenerateQRCode()
{
try
{
var options = new QrOptions(QrErrorCorrectionLevel.High);
var myQr = QrWriter.Write(txt_QR.Text, options);
var style = CreateStyleOptions();
var qrImage = myQr.Save(style);
var fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png";
var fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName);
qrImage.SaveAs(fullPath);
pictureBox.Image = Image.FromFile(fullPath);
}
catch (Exception ex)
{
ShowError("An error occurred during QR code generation or saving", ex.Message);
}
}
private QrStyleOptions CreateStyleOptions()
{
return new QrStyleOptions
{
BackgroundColor = bgColor,
Color = color,
Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"),
Margins = Convert.ToInt32(txt_margin.Value),
Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null
};
}
private void btn_save_Click(object sender, EventArgs e)
{
SaveQRCode();
}
private void SaveQRCode()
{
if (pictureBox.Image == null)
{
MessageBox.Show("There is no QR code to save.", "Error");
return;
}
saveFileDialog.Filter = "PNG Files
*.png
JPEG Files
*.jpg";
saveFileDialog.Title = "Save QR Code";
saveFileDialog.FileName = "QRCode";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName));
MessageBox.Show("QR Code has been saved!", "Success");
}
catch (Exception ex)
{
ShowError("An error occurred while saving the QR code", ex.Message);
}
}
}
private System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath)
{
return System.IO.Path.GetExtension(filePath).ToLower() == ".jpg" ? System.Drawing.Imaging.ImageFormat.Jpeg : System.Drawing.Imaging.ImageFormat.Png;
}
private void btn_reset_Click(object sender, EventArgs e)
{
ResetFields();
}
private void ResetFields()
{
txt_QR.Text = string.Empty;
txt_dimension.Value = 200;
txt_margin.Value = 0;
bgColor = Color.White;
color = Color.Black;
txt_selected_color.BackColor = bgColor;
txt_selected_bgcolor.BackColor = color;
logoBmp = null;
selected_logo.Image = null;
pictureBox.Image = null;
}
private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}
}
}
using IronQr;
using IronSoftware.Drawing;
using Color = IronSoftware.Drawing.Color;
namespace IronQR_QR_Generator_WinForms
{
public partial class QR_Generator : Form
{
string qrCodesDirectory = System.IO.Path.Combine(Application.StartupPath, "QR Codes");
Color bgColor = Color.White;
Color color = Color.Black;
AnyBitmap? logoBmp = null;
public QR_Generator()
{
InitializeComponent();
SetLicenseKey();
EnsureDirectoryExists(qrCodesDirectory);
}
private static void SetLicenseKey()
{
IronQr.License.LicenseKey = "License-Key";
}
private static void EnsureDirectoryExists(string path)
{
if (!System.IO.Directory.Exists(path))
{
System.IO.Directory.CreateDirectory(path);
}
}
private void btn_color_Click(object sender, EventArgs e)
{
UpdateColor(ref color, txt_selected_color, false);
}
private void btn_background_Click(object sender, EventArgs e)
{
UpdateColor(ref bgColor, txt_selected_bgcolor, true);
}
private string ColorToHex(System.Drawing.Color color)
{
return $"#{color.R:X2}{color.G:X2}{color.B:X2}";
}
private void UpdateColor(ref Color targetColor, Control display, bool isBackground)
{
if (select_color.ShowDialog() == DialogResult.OK)
{
var hexColor = ColorToHex(select_color.Color);
targetColor = new Color(hexColor);
display.BackColor = select_color.Color;
}
}
private void btn_logo_Click(object sender, EventArgs e)
{
if (select_logo.ShowDialog() == DialogResult.OK)
{
try
{
logoBmp = new AnyBitmap(select_logo.FileName);
selected_logo.Image = Image.FromFile(select_logo.FileName);
}
catch (Exception ex)
{
ShowError("An error occurred while loading the logo", ex.Message);
}
}
}
private void btn_generate_Click(object sender, EventArgs e)
{
GenerateQRCode();
}
private void GenerateQRCode()
{
try
{
var options = new QrOptions(QrErrorCorrectionLevel.High);
var myQr = QrWriter.Write(txt_QR.Text, options);
var style = CreateStyleOptions();
var qrImage = myQr.Save(style);
var fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png";
var fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName);
qrImage.SaveAs(fullPath);
pictureBox.Image = Image.FromFile(fullPath);
}
catch (Exception ex)
{
ShowError("An error occurred during QR code generation or saving", ex.Message);
}
}
private QrStyleOptions CreateStyleOptions()
{
return new QrStyleOptions
{
BackgroundColor = bgColor,
Color = color,
Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"),
Margins = Convert.ToInt32(txt_margin.Value),
Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null
};
}
private void btn_save_Click(object sender, EventArgs e)
{
SaveQRCode();
}
private void SaveQRCode()
{
if (pictureBox.Image == null)
{
MessageBox.Show("There is no QR code to save.", "Error");
return;
}
saveFileDialog.Filter = "PNG Files
*.png
JPEG Files
*.jpg";
saveFileDialog.Title = "Save QR Code";
saveFileDialog.FileName = "QRCode";
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName));
MessageBox.Show("QR Code has been saved!", "Success");
}
catch (Exception ex)
{
ShowError("An error occurred while saving the QR code", ex.Message);
}
}
}
private System.Drawing.Imaging.ImageFormat DetermineImageFormat(string filePath)
{
return System.IO.Path.GetExtension(filePath).ToLower() == ".jpg" ? System.Drawing.Imaging.ImageFormat.Jpeg : System.Drawing.Imaging.ImageFormat.Png;
}
private void btn_reset_Click(object sender, EventArgs e)
{
ResetFields();
}
private void ResetFields()
{
txt_QR.Text = string.Empty;
txt_dimension.Value = 200;
txt_margin.Value = 0;
bgColor = Color.White;
color = Color.Black;
txt_selected_color.BackColor = bgColor;
txt_selected_bgcolor.BackColor = color;
logoBmp = null;
selected_logo.Image = null;
pictureBox.Image = null;
}
private static void ShowError(string title, string message)
{
MessageBox.Show($"{title}: {message}", "Error");
}
}
}
Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
Namespace IronQR_QR_Generator_WinForms
Partial Public Class QR_Generator
Inherits Form
Private qrCodesDirectory As String = System.IO.Path.Combine(Application.StartupPath, "QR Codes")
Private bgColor As Color = Color.White
Private color As Color = Color.Black
Private logoBmp? As AnyBitmap = Nothing
Public Sub New()
InitializeComponent()
SetLicenseKey()
EnsureDirectoryExists(qrCodesDirectory)
End Sub
Private Shared Sub SetLicenseKey()
IronQr.License.LicenseKey = "License-Key"
End Sub
Private Shared Sub EnsureDirectoryExists(ByVal path As String)
If Not System.IO.Directory.Exists(path) Then
System.IO.Directory.CreateDirectory(path)
End If
End Sub
Private Sub btn_color_Click(ByVal sender As Object, ByVal e As EventArgs)
UpdateColor(color, txt_selected_color, False)
End Sub
Private Sub btn_background_Click(ByVal sender As Object, ByVal e As EventArgs)
UpdateColor(bgColor, txt_selected_bgcolor, True)
End Sub
Private Function ColorToHex(ByVal color As System.Drawing.Color) As String
Return $"#{color.R:X2}{color.G:X2}{color.B:X2}"
End Function
Private Sub UpdateColor(ByRef targetColor As Color, ByVal display As Control, ByVal isBackground As Boolean)
If select_color.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Dim hexColor = ColorToHex(select_color.Color)
targetColor = New Color(hexColor)
display.BackColor = select_color.Color
End If
End Sub
Private Sub btn_logo_Click(ByVal sender As Object, ByVal e As EventArgs)
If select_logo.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
logoBmp = New AnyBitmap(select_logo.FileName)
selected_logo.Image = Image.FromFile(select_logo.FileName)
Catch ex As Exception
ShowError("An error occurred while loading the logo", ex.Message)
End Try
End If
End Sub
Private Sub btn_generate_Click(ByVal sender As Object, ByVal e As EventArgs)
GenerateQRCode()
End Sub
Private Sub GenerateQRCode()
Try
Dim options = New QrOptions(QrErrorCorrectionLevel.High)
Dim myQr = QrWriter.Write(txt_QR.Text, options)
Dim style = CreateStyleOptions()
Dim qrImage = myQr.Save(style)
Dim fileName = $"{DateTime.Now:yyyyMMddHHmmssfff}_QR.png"
Dim fullPath = System.IO.Path.Combine(qrCodesDirectory, fileName)
qrImage.SaveAs(fullPath)
pictureBox.Image = Image.FromFile(fullPath)
Catch ex As Exception
ShowError("An error occurred during QR code generation or saving", ex.Message)
End Try
End Sub
Private Function CreateStyleOptions() As QrStyleOptions
'INSTANT VB TODO TASK: Throw expressions are not converted by Instant VB:
'ORIGINAL LINE: return new QrStyleOptions { BackgroundColor = bgColor, Color = color, Dimensions = txt_dimension.Value > 0 ? Convert.ToInt32(txt_dimension.Value) : throw new ArgumentException("Please select valid dimensions!"), Margins = Convert.ToInt32(txt_margin.Value), Logo = logoBmp != null ? new QrLogo { Bitmap = logoBmp, Width = 50, Height = 50, CornerRadius = 5 } : null };
Return New QrStyleOptions With {
.BackgroundColor = bgColor,
.Color = color,
.Dimensions = If(txt_dimension.Value > 0, Convert.ToInt32(txt_dimension.Value), throw New ArgumentException("Please select valid dimensions!")),
.Margins = Convert.ToInt32(txt_margin.Value),
.Logo = If(logoBmp IsNot Nothing, New QrLogo With {
.Bitmap = logoBmp,
.Width = 50,
.Height = 50,
.CornerRadius = 5
}, Nothing)
}
End Function
Private Sub btn_save_Click(ByVal sender As Object, ByVal e As EventArgs)
SaveQRCode()
End Sub
Private Sub SaveQRCode()
If pictureBox.Image Is Nothing Then
MessageBox.Show("There is no QR code to save.", "Error")
Return
End If
saveFileDialog.Filter = "PNG Files *.png JPEG Files *.jpg"
saveFileDialog.Title = "Save QR Code"
saveFileDialog.FileName = "QRCode"
If saveFileDialog.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
Try
pictureBox.Image.Save(saveFileDialog.FileName, DetermineImageFormat(saveFileDialog.FileName))
MessageBox.Show("QR Code has been saved!", "Success")
Catch ex As Exception
ShowError("An error occurred while saving the QR code", ex.Message)
End Try
End If
End Sub
Private Function DetermineImageFormat(ByVal filePath As String) As System.Drawing.Imaging.ImageFormat
Return If(System.IO.Path.GetExtension(filePath).ToLower() = ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg, System.Drawing.Imaging.ImageFormat.Png)
End Function
Private Sub btn_reset_Click(ByVal sender As Object, ByVal e As EventArgs)
ResetFields()
End Sub
Private Sub ResetFields()
txt_QR.Text = String.Empty
txt_dimension.Value = 200
txt_margin.Value = 0
bgColor = Color.White
color = Color.Black
txt_selected_color.BackColor = bgColor
txt_selected_bgcolor.BackColor = color
logoBmp = Nothing
selected_logo.Image = Nothing
pictureBox.Image = Nothing
End Sub
Private Shared Sub ShowError(ByVal title As String, ByVal message As String)
MessageBox.Show($"{title}: {message}", "Error")
End Sub
End Class
End Namespace
程序运行后,主窗口就会出现,如提供的图片所示。布局整齐地分为输入、样式、输出和操作几个部分。
第一步是在 "输入 QR 文本 "字段中输入数据。这些数据将构成 QR 代码的内容,如 URL 或文本信息。接下来,为了个性化 QR 代码,我们需要点击 "选择徽标 "按钮来选择一个徽标。选择后,徽标会明显地显示在按钮旁边的预览框中,确认其已被纳入 QR 代码设计中。
选择徽标后,我们还可以选择 QR 码的前景色和背景色。点击相应按钮后,所选颜色就会在每个按钮旁边的颜色显示框中显示出来,让我们立即直观地确认自己的选择。
对于这个特定的二维码,我们将尺寸设置为 500,以确保二维码的大小适合我们的需要,并将页边距调整为 20,为二维码提供一个缓冲区,以防止出现扫描问题。
设置好所有输入和样式选项后,我们点击 "生成 QR "按钮生成 QR 代码。应用程序会处理我们的输入,并在输出图片框中显示新创建的 QR 代码。
要保存生成的 QR 代码,我们只需点击 "保存 QR "按钮。该操作会打开一个保存对话框,让我们为二维码图像选择目的地和文件格式。
保存后,会出现一条成功信息,确认 QR 代码已成功存储。
如果我们需要重新开始或创建一个新的二维码,点击 "重置表单 "按钮,表单就会恢复到初始状态,清除所有字段和选择,为下一次生成二维码做好准备。
这是 IronQR 生成的已保存 QR 代码:
总之,本指南将引导您在 C# 应用程序中使用 IronQR 库生成 QR 代码。通过分解从在 Visual Studio 中设置项目、集成 IronQR 库、设计用户友好界面到编写后台逻辑的各个步骤,我们展示了在应用程序中添加 QR 码功能是多么容易。
对于那些有兴趣进一步探索 IronQR 功能的人来说,值得注意的是 IronQR 提供了一个 免费试用 即可开始使用。如果您决定将 IronQR 集成到您的项目中,许可证起价为 $749,可为专业级 QR 代码生成提供经济高效的解决方案。