zxingli 2020-01-03
using System.Drawing; using ZXing; using ZXing.QrCode; /// <summary> /// 生成二维码 /// </summary> /// <param name="dirPath">路径</param> /// <returns></returns> private string GenerateQRCode(string dirPath) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.DisableECI = true; //设置内容编码 options.CharacterSet = "UTF-8"; //设置二维码的宽度和高度 options.Width = 500;//500 options.Height = 500;//500 //设置二维码的边距,单位不是固定像素 options.Margin = 1; writer.Options = options; StringBuilder content = new StringBuilder(); content.AppendFormat("SUCCESS:创建二维码成功!"); Bitmap map = writer.Write(content.ToString()); string fileName = @dirPath + @"QrCode.png"; map.Save(fileName, ImageFormat.Png); map.Dispose(); return fileName; }