在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
新建一个html辅助类 public static class HtmlHelperExtensions { public static IHtmlString GenerateRelayQrCode(this HtmlHelper html,string qrValue,int height = 250, int width = 250, int margin = 0) { var barcodeWriter = new BarcodeWriter { Format = BarcodeFormat.QR_CODE, Options = new EncodingOptions { Height = height, Width = width, Margin = margin } }; using (var bitmap = barcodeWriter.Write(qrValue)) using (var stream = new MemoryStream()) { bitmap.Save(stream, ImageFormat.Gif); var img = new TagBuilder("img"); img.MergeAttribute("alt", "your alt tag"); img.Attributes.Add("src", String.Format("data:image/gif;base64,{0}", Convert.ToBase64String(stream.ToArray()))); return MvcHtmlString.Create(img.ToString(TagRenderMode.SelfClosing)); } } }
asp.net mvc view中调用 @Html.GenerateRelayQrCode("a") |
请发表评论