首页 > 代码库 > c# 二维码 显示

c# 二维码 显示

 需要引用 ThoughtWorks.QRCode.dll 网上可下载//方法public ActionResult GenerateQRCode(string content){try{_fileLog.Info("GenerateQRCode|开始生成二维码");if (null != content){//初始化二维码生成工具var qrCodeEncoder = new QRCodeEncoder{QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE,QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M,QRCodeVersion = 0,QRCodeScale = 4};//将字符串生成二维码图片var image = qrCodeEncoder.Encode(content);var ms = new MemoryStream();image.Save(ms, ImageFormat.Png);Response.BinaryWrite(ms.GetBuffer());Response.End();}_fileLog.Info("CloudCardController|GenerateQRCode|成功生成二维码");}catch (Exception ex){_fileLog.Error("GenerateQRCode|生成二维码出现异常,异常信息:" + ex.Message);}return View();}页面使用<img src=http://www.mamicode.com/"@Url.Action("GenerateQRCode", "CloudCard", new { content = @Model.CardCode })" alt=" " class=" event_img img-responsive" />

 

c# 二维码 显示