本示例是zxing生成二维码信息,需要应用zxing。
public static class QRCode { public static Bitmap GetBitmap(string sContent, int iWidth, int iHeight) { BarcodeWriter writer = new BarcodeWriter(); writer.Format = BarcodeFormat.QR_CODE; QrCodeEncodingOptions options = new QrCodeEncodingOptions(); options.DisableECI = true; //设置内容编码 options.CharacterSet = "UTF-8"; //设置二维码的宽度和高度 options.Width = iWidth; options.Height = iHeight; //设置二维码的边距,单位不是固定像素 options.Margin = 0; // 设置周围空白边距 writer.Options = options; return writer.Write(sContent); } public static string GetBitmapBase64String(string sContent, int iWidth, int iHeight) { Bitmap imgBitmap = GetBitmap(sContent, iWidth, iHeight); string filename = System.Windows.Forms.Application.StartupPath + "\\QrCodeTemp.jpg"; imgBitmap.Save(filename, ImageFormat.Jpeg); MemoryStream ms = new MemoryStream(); imgBitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] arr = new byte[ms.Length]; ms.Position = 0; ms.Read(arr, 0, (int)ms.Length); ms.Close(); imgBitmap.Dispose(); string strBaser64 = Convert.ToBase64String(arr); return strBaser64; } } }
下载地址:
「zxing.dll」https://www.aliyundrive.com/s/CtoCqKCwkcy