using System.Drawing; namespace DownKyi.Core.Utils { public static class QRCode { /// /// 生成二维码 /// /// 信息 /// 版本 1 ~ 40 /// 像素点大小 /// 图标路径 /// 图标尺寸 /// 图标边框厚度 /// 二维码白边 /// 位图 public static Bitmap EncodeQRCode(string msg, int version, int pixel, string icon_path, int icon_size, int icon_border, bool white_edge) { QRCoder.QRCodeGenerator code_generator = new QRCoder.QRCodeGenerator(); QRCoder.QRCodeData code_data = code_generator.CreateQrCode(msg, QRCoder.QRCodeGenerator.ECCLevel.H/* 这里设置容错率的一个级别 */, true, false, QRCoder.QRCodeGenerator.EciMode.Utf8, version); QRCoder.QRCode code = new QRCoder.QRCode(code_data); Bitmap icon; if (icon_path == null || icon_path == "") { icon = null; } else { icon = new Bitmap(icon_path); } Bitmap bmp = code.GetGraphic(pixel, Color.Black, Color.White, icon, icon_size, icon_border, white_edge); return bmp; } } }