//二维码生成 @using Gma.QrCodeNet.Encoding; @using Gma.QrCodeNet.Encoding.Windows.Render; @functions { public static string QRCode(string data) { using (var ms = new System.IO.MemoryStream()) { QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.M); QrCode qrCode = qrEncoder.Encode(data); var render = new GraphicsRenderer(new FixedModuleSize(4, QuietZoneModules.Two)); render.WriteToStream(qrCode.Matrix, System.Drawing.Imaging.ImageFormat.Png, ms); byte[] bytes = new byte[ms.Length]; ms.Position = 0; ms.Read(bytes, 0, (int)ms.Length); String Base64String = Convert.ToBase64String(bytes); return Base64String; } } }
//前端调用 @{ var url="这里填写网址"; var code = razor.QRCode(url); } //输出 <img src="data:image/png;base64,@code"> //1.说明需要去下载 Gma.QrCodeNet.Encoding.dll 放在bin目录下 //2.做了一个二维码生成,但是不知道二维码解析怎么做,有站点的请告诉一下,谢谢!