12345678910111213141516171819202122232425262728293031323334 |
- using QRCoder;
- using ShareWifi.Model;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ShareWifi.Utils
- {
- class QRUtils
- {
- /// <summary>
- /// 根据 data 生成二维码
- /// </summary>
- /// <param name="data"></param>
- public static QRModel genQR(string data)
- {
- QRCodeGenerator qrGenerator = new QRCodeGenerator();
- QRCodeData qrCodeData = qrGenerator.CreateQrCode(data, QRCodeGenerator.ECCLevel.Q);
- QRCode qrCode = new QRCode(qrCodeData);
- Bitmap bitmap = qrCode.GetGraphic(5);
- //保存图片
- string fileName = System.DateTime.Now.ToString("yyyy-MM-dd-HH_mm_ss") + ".jpg";
- string filePath = System.Environment.CurrentDirectory;
- //bitmap.Save(filePath + "/" + fileName, ImageFormat.Jpeg);
- return new QRModel(filePath, fileName, bitmap);
- }
- }
- }
|