生成二维码 打上自定义logo

 private void RenderQrCode(string Code)
        {
            try
            {
                string level = "Q";
                string url = ZConfig.GetConfigString("qudaourl") + Code;
                QRCodeGenerator.ECCLevel eccLevel = (QRCodeGenerator.ECCLevel)(level == "L" ? 0 : level == "M" ? 1 : level == "Q" ? 2 : 3);
                using (QRCodeGenerator qrGenerator = new QRCodeGenerator())
                {
                    using (QRCodeData qrCodeData = qrGenerator.CreateQrCode(url, eccLevel))
                    {
                        using (QRCode qrCode = new QRCode(qrCodeData))
                        {
                            Bitmap Image = qrCode.GetGraphic(10, Color.Black, Color.White,
                             FileUploader.GetIconBitmap(), (int)8);
                            string s = ZConfig.GetConfigString("ImageRootPath") + @"qudao" + Code + ".jpg";
                            Image.Save(s);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                NLogger.Error("渠道二维码生成:" + ex.ToString());
            }
        }
  public class FileUploader
    {
        public static Bitmap GetIconBitmap()
        {
            Bitmap img = null;
            try
            {
                string directory = HttpContext.Current.Server.MapPath("\") + "Images/icc.png";
                img = new Bitmap(directory);
            }
            catch (Exception)
            {
            }

            return img;
        }
    }

参考:

https://github.com/codebude/QRCoder/

原文地址:https://www.cnblogs.com/lyl6796910/p/6148276.html