ThoughtWorks.QRCode.dll:

1、ThoughtWorks.QRCode.dll

2、通过 NuGet 添加

C# 二维码 ThoughtWorks.QRCode.dll-LMLPHP

后台代码:

using System;
using System.Drawing;
using System.Text;
using ThoughtWorks.QRCode.Codec; namespace ConsoleTest
{
public class Test
{
#region 生成二维码
/// <summary>
/// 生成二维码
/// </summary>
/// <param name="number"></param>
/// <returns></returns>
private static string QRCode()
{
System.Drawing.Bitmap bt;
string enCodeString = "http://www.baidu.com"; QRCodeEncoder qrCodeEncoder = new QRCodeEncoder();
qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE;//编码方式(注意:BYTE能支持中文,ALPHA_NUMERIC扫描出来的都是数字)
qrCodeEncoder.QRCodeScale = ;//大小(值越大生成的二维码图片像素越高)
qrCodeEncoder.QRCodeVersion = ;//版本(注意:设置为0主要是防止编码的字符串太长时发生错误)
qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M;//错误效验、错误更正(有4个等级)
qrCodeEncoder.QRCodeBackgroundColor = Color.Yellow;//背景色
qrCodeEncoder.QRCodeForegroundColor = Color.Green;//前景色 bt = qrCodeEncoder.Encode(enCodeString, Encoding.UTF8); string filename = "code";
string file_path = AppDomain.CurrentDomain.BaseDirectory + "QRCode\\";
string codeUrl = file_path + filename + ".jpg"; //根据文件名称,自动建立对应目录
if (!System.IO.Directory.Exists(file_path))
System.IO.Directory.CreateDirectory(file_path); bt.Save(codeUrl);//保存图片
return codeUrl;
}
#endregion
}
}

二维码效果:

C# 二维码 ThoughtWorks.QRCode.dll-LMLPHP

05-15 09:43