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 { /// /// 根据 data 生成二维码 /// /// 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); } } }