41 lines
1.1 KiB
C#
41 lines
1.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net.NetworkInformation;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using QRCoder;
|
|
using RestSharp.Extensions;
|
|
namespace New_College.Common
|
|
{
|
|
public static class QrCodeHelper
|
|
{
|
|
/// <summary>
|
|
/// 生成二维码
|
|
/// </summary>
|
|
/// <param name="url"></param>
|
|
/// <returns></returns>
|
|
public static byte[] GerQrCodeStream(string url)
|
|
{
|
|
|
|
// 创建 QRCodeGenerator 实例
|
|
QRCodeGenerator qrGenerator = new QRCodeGenerator();
|
|
|
|
// 创建 QRCodeData 实例
|
|
QRCodeData qrCodeDataObject = qrGenerator.CreateQrCode(url, QRCodeGenerator.ECCLevel.Q);
|
|
|
|
// 创建 PngByteQRCode 实例
|
|
PngByteQRCode qrCode = new PngByteQRCode(qrCodeDataObject);
|
|
|
|
// 获取二维码图片的字节数组
|
|
var qrCodeImageBytes = qrCode.GetGraphic(8); // 图片大小
|
|
|
|
|
|
return qrCodeImageBytes;
|
|
}
|
|
|
|
|
|
}
|
|
} |