mvc4 net4.0
1、引用附件的DLL文件
2、两个函数即可
#region 生成二维码 public ActionResult getQrCode() { using (var ms = new MemoryStream()) { string stringtest = "这里是二维码内容"; GetQRCode1(stringtest, ms); Response.ContentType = "image/Png"; Response.OutputStream.Write(ms.GetBuffer(), 0, (int)ms.Length); Response.End(); } return View(); } public bool GetQRCode1(string strContent, MemoryStream ms) { ErrorCorrectionLevel Ecl = ErrorCorrectionLevel.M; //误差校正水平 string Content = strContent;//待编码内容 QuietZoneModules QuietZones = QuietZoneModules.Two; //空白区域 int ModuleSize = 12;//大小 var encoder = new QrEncoder(Ecl); QrCode qr; if (encoder.TryEncode(Content, out qr))//对内容进行编码,并保存生成的矩阵 { var render = new GraphicsRenderer(new FixedModuleSize(ModuleSize, QuietZones)); render.WriteToStream(qr.Matrix, ImageFormat.Png, ms); } else { return false; } return true; } #endregion
时间: 2024-10-18 04:47:43