public ReturnValue SendImage(int agentID, string title, string bodyText, string toParty, string toTag, string toUser)
        {
            ReturnValue val = new ReturnValue
            {
                Success = false
            };

            try
            {
                string path = "C:/Images/";
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
                string str2 = title + ".html";
                if (!File.Exists(path + str2))
                {
                    File.Create(path + str2);
                }
                Bitmap webSiteThumbnail = WebSiteThumbnail.GetWebSiteThumbnail(path + str2, bodyText);
                string str3             = title + ".Png";
                webSiteThumbnail.Save(path + str3, ImageFormat.Png);
                val = this.enterprise.UploadMedia("image", path + str3);
                if (!val.Success)
                {
                    return(val);
                }
                return(this.SendImage(agentID, val.Result.ToString(), toParty, toTag, toUser));
            }
            catch (Exception exception)
            {
                val.Message = exception.Message + exception.StackTrace;
            }
            return(val);
        }
        /// <summary>
        /// 生成砍价分享图片,返回图片名称
        /// </summary>
        /// <param name="reservePrice">砍价---底价</param>
        /// <param name="pid">砍价---商品</param>
        private string CreateBargainShareImage(decimal reservePrice, int pid, string shareImage1 = "")
        {
            string result = string.Empty;

            try
            {
                string path = "/upload/bargainshare/";
                #region  掉原图
                if (!string.IsNullOrWhiteSpace(shareImage1))
                {
                    if (File.Exists(Server.MapPath(path + shareImage1)))
                    {
                        File.Delete(Server.MapPath(path + shareImage1));
                    }
                }
                #endregion
                //string html_url = "http://"+ Request.Url.Host+(Request.Url.Port>0?":"+Request.Url.Port:"") +"/Admin/bargainshare/t1.aspx?reservePrice=" + reservePrice + "&pid=" + pid;
                string html_url = "http://" + Request.Url.Host + "/Admin/bargainshare/t1.aspx?reservePrice=" + reservePrice + "&pid=" + pid;
                Bitmap m_Bitmap = WebSiteThumbnail.GetWebSiteThumbnail(html_url, 320, 256, 320, 256);
                string imgName  = "xcx_bargainshare_" + Guid.NewGuid().ToString() + ".png";
                if (!Directory.Exists(Server.MapPath(path)))
                {
                    Directory.CreateDirectory(Server.MapPath(path));
                }
                m_Bitmap.Save(Server.MapPath(path + imgName), System.Drawing.Imaging.ImageFormat.Png);//JPG、GIF、PNG等均可
                result = path + imgName;
            }
            catch (Exception ex)
            {
                new TxtLog(Server.MapPath("/apilog/")).Write("-----生成砍价分享图片错误:" + ex + "----");
            }
            return(result);
        }
Exemple #3
0
        /// <summary>
        /// 高质量存图
        /// </summary>
        /// <returns>生成准考证图片地址</returns>
        public string getSavePicPathH(string id)
        {
            string url      = string.Format("{0}://{1}{2}", Request.Url.Scheme, Request.Url.Authority, Url.Content("~"));
            Bitmap m_Bitmap = WebSiteThumbnail.GetWebSiteThumbnail(url + "/EnrolSysStu/GenerateZkzPng/" + id, 690, 955, 690, 955);

            ImageCodecInfo myImageCodecInfo;

            System.Drawing.Imaging.Encoder myEncoder;
            EncoderParameter  myEncoderParameter;
            EncoderParameters myEncoderParameters;

            myImageCodecInfo    = GetEncoderInfo("image/png");//jpeg
            myEncoder           = System.Drawing.Imaging.Encoder.Quality;
            myEncoderParameters = new EncoderParameters(1);
            // Save the bitmap as a JPEG file with quality level 75.
            myEncoderParameter           = new EncoderParameter(myEncoder, 100L);
            myEncoderParameters.Param[0] = myEncoderParameter;


            // Response.BinaryWrite(buff);
            //var ZkzPath = HttpRuntime.AppDomainAppPath.ToString() + "ZhunKaoZheng";
            var ZkzPath = "ZhunKaoZheng";

            CreateDir(ZkzPath);
            var picName = Guid.NewGuid() + ".png";

            //m_Bitmap.Save(HttpRuntime.AppDomainAppPath.ToString() + ZkzPath + "\\aa.png", System.Drawing.Imaging.ImageFormat.Png);
            m_Bitmap.Save(HttpRuntime.AppDomainAppPath.ToString() + ZkzPath + "\\" + picName, myImageCodecInfo, myEncoderParameters);
            m_Bitmap.Dispose();
            return(picName);
        }
Exemple #4
0
        private void SaveImg()
        {
            string html_url = "http://" + Request.Url.Host + (Request.Url.Port > 0 ? ":" + Request.Url.Port : "") + "/Admin/bargainshare/t1.aspx?reservePrice=0&pid=1005";
            Bitmap m_Bitmap = WebSiteThumbnail.GetWebSiteThumbnail(html_url, 320, 256, 320, 256);
            //Bitmap m_Bitmap = WebSnapshotsHelper.GetWebSiteThumbnail(html_url, 640, 380, 640, 380);
            string imgName = "xcx_bargainshare_" + Guid.NewGuid().ToString() + ".png";
            string path    = "/upload/bargainshare/";

            if (!Directory.Exists(Server.MapPath(path)))
            {
                Directory.CreateDirectory(Server.MapPath(path));
            }
            m_Bitmap.Save(Server.MapPath(path + imgName), System.Drawing.Imaging.ImageFormat.Png);//JPG、GIF、PNG等均可
            ScriptHelper.AlertFront("保存成功");
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            return;

            Bitmap       m_Bitmap = WebSiteThumbnail.GetWebSiteThumbnail("http://pbie.chinacloudsites.cn/Dashboard/Report?reportId=0a46b754-f5a3-4c19-b032-c6599bdb2f4d", 4600, 4600, 4600, 4600);
            MemoryStream ms       = new MemoryStream();

            string FileName = DateTime.Now.ToString("yyyyMMddhhmmss");

            string filePath      = "SnapPic/";
            string severFilePath = Server.MapPath(filePath);

            //If directory does not exist
            if (!Directory.Exists(severFilePath))
            { // if it doesn't exist, create
                System.IO.Directory.CreateDirectory(severFilePath);
            }

            using (MemoryStream memory = new MemoryStream())
            {
                using (FileStream fs = new FileStream(Server.MapPath("SnapPic/" + FileName + ".jpg"), FileMode.Create, FileAccess.ReadWrite))
                {
                    m_Bitmap.Save(memory, ImageFormat.Jpeg);
                    byte[] bytes = memory.ToArray();
                    fs.Write(bytes, 0, bytes.Length);
                }
            }


            //m_Bitmap.Save(Server.MapPath("SnapPic/" + FileName + ".jpg"));//保存截图到SnapPic目录下

            //m_Bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);//JPG、GIF、PNG等均可

            byte[] buff = ms.ToArray();
            //Response.BinaryWrite(buff);

            //Thread NewTh = new Thread(CaptureImage);
            //NewTh.SetApartmentState(ApartmentState.STA);//必须启动单元线程
            //NewTh.Start();
        }
        /// <summary>
        /// 抓取HomePage图片
        /// </summary>
        public void HtmlImageCapture()
        {
            string url     = System.Web.HttpContext.Current.Request.Url.AbsoluteUri; //AbsoluteUri = "http://localhost:58321/Journal/StaticHtml"
            int    start   = url.IndexOf("//");
            int    end     = url.IndexOf("/", start + 2);
            string urlHead = url.Substring(0, end + 1);
            //返回的页面截屏二进制对象
            Bitmap m_Bitmap = WebSiteThumbnail.GetWebSiteThumbnail(urlHead, 800, 960, 800, 960); //http://localhost:58321/
            //m_Bitmap.Save("D:/XXX/" + "text.png", System.Drawing.Imaging.ImageFormat.Png);

            string outputDir = HttpContext.Server.MapPath(ConfigurationManager.AppSettings["HtmlOutput"]) + "\\" + currentJournalEntity.JournalName + "\\mail\\images\\";

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }
            string targetFilePath = outputDir + "index.jpg";

            //在这个页面上再绘制banner图片
            using (Graphics gp = Graphics.FromImage(m_Bitmap))
            {
                string bannerImg = HttpContext.Server.MapPath("~") + "\\images\\banner_4.jpg"; //banner_1~4.jpg 可以定期更换
                gp.DrawImage(Image.FromFile(bannerImg), 47, 131, 702, 184);                    //必须设置比例,否则会失真
            }

            using (FileStream fs = new FileStream(targetFilePath, FileMode.Create))
            {
                ImageCodecInfo imageCodeInfo             = ImageOperation.GetEncoderInfo("image/jpeg");
                System.Drawing.Imaging.Encoder myEncoder = System.Drawing.Imaging.Encoder.Quality;
                EncoderParameters myEncoderParameters    = new EncoderParameters(1);
                myEncoderParameters.Param[0] = new EncoderParameter(myEncoder, 85L);
                m_Bitmap.Save(fs, imageCodeInfo, myEncoderParameters);
            }

            //MemoryStream ms = new MemoryStream();
            //m_Bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Png);//JPG、GIF、PNG等均可
                        //byte[] buff = ms.ToArray();
                        //Response.BinaryWrite(buff);
        }