protected void btnSnapshot_Click(object sender, EventArgs e)
        {
            string url  = txtUrl.Text;
            string html = txtHtml.Text;

            string fold        = "~/Images/Snapshot/";//图片存放目录
            string physicsFold = Server.MapPath(fold);

            try
            {
                string guid = "";
                if (string.IsNullOrEmpty(url))
                {
                    guid = WebPreview.GetHtmlPreview(html, physicsFold);
                }
                else
                {
                    guid = WebPreview.GetUrlPreview(url, physicsFold);
                }
                string fileName = "img_" + guid + ".jpg";
                imgPrevew.ImageUrl = "~/Images/Snapshot/" + fileName;
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 2
0
 private void btnSnap2_Click(object sender, EventArgs e)
 {
     if (this.txtUrl.Text.Length == 0)
     {
         return;
     }
     this.pictureBox1.Image = WebPreview.GetWebPreview(new Uri(this.txtUrl.Text), Screen.PrimaryScreen.Bounds.Size);
 }
        void ReleaseDesignerOutlets()
        {
            if (WebPreview != null)
            {
                WebPreview.Dispose();
                WebPreview = null;
            }

            if (ZoomLevel != null)
            {
                ZoomLevel.Dispose();
                ZoomLevel = null;
            }

            if (StatusBar != null)
            {
                StatusBar.Dispose();
                StatusBar = null;
            }
        }
Ejemplo n.º 4
0
        public byte[] GetHeatMapImage(string beginTime, string endTime, string url, string urlEncoding, int screenWidth, int screenHeight)
        {
            /*
             * 1.获取Url网页快照
             * 2.查询数据库访客点击表记录
             * 3.校正偏移访客点击坐标点数据
             * 4.绘制访客点击热力图
             * 5.缓存查询结果并返回热力图
             */

            try
            {
                //获取网页快照
                var webPageImage = WebPreview.GetWebPreview(new Uri(url), 30000, screenWidth, screenHeight, true);

                //设置heatPoint
                var apiUrl = string.Format(ApiFormat, urlEncoding, beginTime, endTime, screenWidth, screenHeight);

                var json = GetHtmlSource(apiUrl);

                var heatMapMessage = JsonConvert.DeserializeObject <List <HeatMapMessage> >(json);

                var heatPoints = new List <HeatPoint>();
                if (heatMapMessage != null)
                {
                    heatPoints = heatMapMessage.Select(m => new HeatPoint {
                        W = 1, X = m.X, Y = m.Y
                    }).ToList();
                }

                //生成热力图
                var heatMapMaker = new HeatMapMaker
                {
                    Width      = webPageImage.Width,
                    Height     = webPageImage.Height,
                    Radius     = 20,
                    ColorRamp  = ColorRamp.THERMAL,
                    HeatPoints = heatPoints,
                    Opacity    = 0.8f
                };

                var heatMapImage = heatMapMaker.MakeHeatMap().Result;

                //场景图与热力图合并
                using (var g = Graphics.FromImage(webPageImage))
                {
                    var rectangle = new Rectangle(0, 0, webPageImage.Width, webPageImage.Height);
                    g.DrawImage(heatMapImage, rectangle);
                }

                //加入缓存
                var imageBytes = webPageImage.ToImageBytes();

                webPageImage.Dispose();

                return(imageBytes);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);

                return(null);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Prints the preview.
 /// </summary>
 public void PrintPreview()
 {
     WebPreview.Print(this);
 }