private void GenerateSvg(TagHelperOutput output, string content, BarcodeFormat barcodeformat, int width, int height, int margin, string alt) { var qrWriter = new ZXing.BarcodeWriterSvg { Format = barcodeformat, Options = new QrCodeEncodingOptions { Height = height, Width = width, Margin = margin } }; var svgImage = qrWriter.Write(content); output.TagName = "img"; output.Attributes.Clear(); output.Attributes.Add("width", svgImage.Width); output.Attributes.Add("height", svgImage.Height); output.Attributes.Add("alt", alt); output.Attributes.Add("src", new Microsoft.AspNetCore.Html.HtmlString( String.Format("data:image/svg+xml;{0}", svgImage.Content))); }
public override void Process(TagHelperContext context, TagHelperOutput output) { if (String.IsNullOrEmpty(this.Content)) { return; } var encodingOpts = this.CreateOptions(); var qrWriter = new ZXing.BarcodeWriterSvg { Format = this.ConvertBarcodeFormat(this.BarcodeFormat), Options = encodingOpts, }; var svgImage = qrWriter.Write(this.Content); var base64 = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(svgImage.Content)); var src = $"data:image/svg+xml;base64,{base64}"; output.TagName = "img"; output.Attributes.Clear(); output.Attributes.Add("width", this.Width); output.Attributes.Add("height", this.Height); output.Attributes.Add("alt", this.Alt); output.Attributes.Add("src", src); }
public static void Main(string[] args) { var myIp = GetLocalIPv4(NetworkInterfaceType.Ethernet); if (string.IsNullOrWhiteSpace(myIp)) { myIp = GetLocalIPv4(NetworkInterfaceType.Wireless80211); } else if (string.IsNullOrWhiteSpace(myIp)) { myIp = "127.0.0.1"; } Console.WriteLine(myIp); var w = new ZXing.BarcodeWriterSvg(); w.Format = BarcodeFormat.QR_CODE; var image = w.Write($"http://{myIp}:54856"); System.IO.Directory.CreateDirectory(System.IO.Path.Combine(".", "wwwroot", "images")); System.IO.File.WriteAllText(System.IO.Path.Combine(".", "wwwroot", "images", "barcode.svg"), image.Content); BuildWebHost(args).Run(); }