Пример #1
0
        /// <summary>
        /// 生成红包码
        /// </summary>
        /// <param name="hbUrl0">红包码</param>
        /// <param name="HbDir">收款码保存路径</param>
        /// <returns></returns>
        public static string genHbPic(string hbUrl0, string HbDir)
        {
            string hbUrl   = hbUrl0.Trim();
            string picName = "";

            if (hbUrl.ToLower().StartsWith("https://qr.alipay.com/"))
            {
                picName = hbUrl.Substring("https://qr.alipay.com/".Length) + ".png";
            }
            else
            {
                picName = MD5.Encrypt(hbUrl) + ".png";
            }

            string picPath = AppDomain.CurrentDomain.BaseDirectory + HbDir + picName;

            if (!File.Exists(picPath))
            {
                Bitmap pic = QrTool_HB.ToHbPic(hbUrl);   // 生成红包码
                picName = QrTool_HB.Save(pic, HbDir, picName);
            }

            if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + HbDir + picName))
            {
                return(picName);
            }
            else
            {
                return("");
            }
        }
Пример #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            String dirPath    = Request["path"];
            String reName     = Request["reName"];
            bool   isDownload = (Request["download"] != null && Request["download"].Equals("true"));

            if (dirPath == null)
            {
                Response.Write(Request.Url + "?" + "path=" + "http://t2.hddhhn.com/uploads/tu/201707/115/56.jpg" + "&" + "reName=" + "0.png" + "&" + "download=" + "false");
            }
            else
            {
                Bitmap img = QrTool_HB.ToHbPic(dirPath);
                if (reName == null)
                {
                    reName = "0.png";
                }

                // 输出图像
                try
                {
                    MemoryStream ms = new MemoryStream();
                    img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Response.ClearContent();
                    Response.ContentType = "Image/png";
                    Response.AddHeader("Content-Disposition", (isDownload ? "attachment; " : "") + "filename=" + HttpUtility.UrlEncode(reName, System.Text.Encoding.UTF8));
                    Response.BinaryWrite(ms.ToArray());
                }
                catch (Exception ex) { }
            }
        }