http://www.sufeinet.com/plugin.php?id=keke_group

苏飞论坛

 找回密码
 马上注册

QQ登录

只需一步,快速开始

分布式系统框架(V2.0) 轻松承载百亿数据,千万流量!讨论专区 - 源码下载 - 官方教程

HttpHelper爬虫框架(V2.7-含.netcore) HttpHelper官方出品,爬虫框架讨论区 - 源码下载 - 在线测试和代码生成

HttpHelper爬虫类(V2.0) 开源的爬虫类,支持多种模式和属性 源码 - 代码生成器 - 讨论区 - 教程- 例子

查看: 3391|回复: 6

[其他] Web自动截图功能

[复制链接]
发表于 2013-12-6 10:00:37 | 显示全部楼层 |阅读模式
[Bash shell] 纯文本查看 复制代码
 protected void Page_Load(object sender, EventArgs e)
        {
            this.CreateImage();
            this.Cutpicture();
        }
        private void CreateImage()
        {
            //string district = Session["District"].ToString();
            //string channel = Session["Channel"].ToString();
            //string timeselect = Session["TimeSelect"].ToString();
            //string indicator = Session["Indicator"].ToString();
           // string title = ""+channel.ToString()+""+""+indicator.ToString()+""+"统计图";
            //定义所画图形的大小
            int height = 400, width = 540;
            Bitmap bitmap = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bitmap);
            //定义一些字体
            g.Clear(Color.White);
            Font font = new System.Drawing.Font("Arial", 5, FontStyle.Regular);
            Font font1 = new System.Drawing.Font("宋体", 20, FontStyle.Regular);
            Font font2 = new System.Drawing.Font("Arial", 10, FontStyle.Regular);

            //画背景色
            LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0,0,bitmap.Width,bitmap.Height), Color.Blue, Color.Blue, 1.2f, true);
            g.FillRectangle(Brushes.AliceBlue, 0, 0, width, height);
            Brush brush1 = new SolidBrush(Color.Blue);
            Brush brush2 = new SolidBrush(Color.SaddleBrown);

            //字体显示位置
            g.DrawString("hah", font1, brush1, new PointF(100, 30));

            //画图片的边框线(最外头的矩形框)
            g.DrawRectangle(new Pen(Color.Blue), 0, 0, bitmap.Width-1,bitmap.Height-1);
            Pen mypen = new Pen(brush, 1);
            Pen mypen2 = new Pen(Color.Red, 2);

            //绘制线条
            //绘制纵向线条
            int x = 45;
            for (int i = 0; i < 24; i++)
            {
                g.DrawLine(mypen, x, 80, x, 350);
                x = x + 20;
            }
            Pen mypen1 = new Pen(Color.Blue, 2);
            g.DrawLine(mypen1, x - 480, 80, x - 480, 350);

            //绘制横向线条
            int y = 100;
            for (int i = 0; i < 5; i++)
            {
                g.DrawLine(mypen, 45, y, 530, y);
                y = y + 50;
            }
            g.DrawLine(mypen1, 45, y, 530, y);

            //x轴
            string[] n = { "00:00\n-1:00\n", "1:00\n-2:00\n", "2:00\n-3:00\n", "3:00\n-4:00\n", "4:00\n-5:00\n", "5:00\n-6:00\n", "6:00\n-7:00\n", "7:00\n-8:00\n", "8:00\n-9:00\n", "9:00\n-10:00\n", "10:00\n-11:00\n", "11:00\n-12:00\n", "12:00\n-13:00\n", "13:00\n-14:00\n", "14:00\n-15:00\n", "15:00\n-16:00\n", "16:00\n-17:00\n", "17:00\n-18:00\n", "18:00\n-19:00\n", "19:00\n-20:00\n", "20:00\n-21:00\n", "21:00\n-22:00\n", "22:00\n-23:00\n", "23:00\n-00:00\n" };
            x = 45;
            for (int i = 0; i < 24; i++)
            {
                g.DrawString(n[i].ToString(), font, Brushes.Red, x, 355);
                x = x + 20;
            }
            //y轴
            string[] m = {"2.5", "2", "1.5", "1", "0.5", "0"};
            y = 90;
            for (int i = 0; i < 6; i++)
            {
                g.DrawString(m[i].ToString(), font2, Brushes.Red, 15, y);
                y = y + 50;
            }

            PRealData pRealData = new PRealData();
            string str = "select* from RealTimeData";
            string num = "select UserName from Customer";
            int CustomerSum = pRealData.CustomerSum(num);
            int[] PerChannPday = new int[24];
          //   int[] PerHourSum = new int[24];
            int[] Count1 = new int[24];
            PerChannPday = pRealData.PerChannPDay(str,"CCTV-1");
          //  PerHourSum = pRealData.PerHourSum(str);
            for (int i = 0; i < 24; i++)
            {
                Count1[i] = PerChannPday[i]*1000/(60 * CustomerSum);
            }
            //   GridView1.DataSource = Count1;
            //  GridView1.DataBind();
            SolidBrush mybrush = new SolidBrush(Color.Red);
            Point[] points1 = new Point[24];
            points1[0].X = 45; points1[0].Y = 350 - Count1[0];
            points1[1].X = 65; points1[1].Y = 350 - Count1[1];
            points1[2].X = 85; points1[2].Y = 350 - Count1[2];
            points1[3].X = 105; points1[3].Y = 350 - Count1[3];
            points1[4].X = 125; points1[4].Y = 350 - Count1[4];
            points1[5].X = 145; points1[5].Y = 350 - Count1[5];
            points1[6].X = 165; points1[6].Y = 350 - Count1[6];
            points1[7].X = 185; points1[7].Y = 350 - Count1[7];
            points1[8].X = 205; points1[8].Y = 350 - Count1[8];
            points1[9].X = 225; points1[9].Y = 350 - Count1[9];
            points1[10].X = 245; points1[10].Y = 350 - Count1[10];
            points1[11].X = 265; points1[11].Y = 350 - Count1[11];
            points1[12].X = 285; points1[12].Y = 350 - Count1[12];
            points1[13].X = 305; points1[13].Y = 350 - Count1[13];
            points1[14].X = 325; points1[14].Y = 350 - Count1[14];
            points1[15].X = 345; points1[15].Y = 350 - Count1[15];
            points1[16].X = 365; points1[16].Y = 350 - Count1[16];
            points1[17].X = 385; points1[17].Y = 350 - Count1[17];
            points1[18].X = 405; points1[18].Y = 350 - Count1[18];
            points1[19].X = 425; points1[19].Y = 350 - Count1[19];
            points1[20].X = 445; points1[20].Y = 350 - Count1[20];
            points1[21].X = 465; points1[21].Y = 350 - Count1[21];
            points1[22].X = 485; points1[22].Y = 350 - Count1[22];
            points1[23].X = 505; points1[23].Y = 350 - Count1[23];
            g.DrawLines(mypen2, points1);  //绘制折线

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
            Response.ClearContent();
            Response.ContentType = "image/Jpeg";
            Response.BinaryWrite(ms.ToArray());

        }
        private void Cutpicture()
        {
            Rectangle R = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
            R.Width = 540;
            R.Height = 400;
            System.Drawing.Image img = new Bitmap(R.Width, R.Height);
            Graphics G = Graphics.FromImage(img);
            G.CopyFromScreen(new Point(0,86), new Point(0, 0), new Size(R.Width, R.Height));
            IntPtr dc = G.GetHdc();
            G.ReleaseHdc(dc);
            G.Dispose();
            img.Save("c:\\a.jpg");
        }


老大这个是截图程序,【想着如何页面加载完成了】,然后再自动截图。
画图的一些参数要其他页面传过来。
谢谢!


1. 开通SVIP会员,免费下载本站所有源码,不限次数据,不限时间
2. 加官方QQ群,加官方微信群获取更多资源和帮助
3. 找站长苏飞做网站、商城、CRM、小程序、App、爬虫相关、项目外包等点这里
发表于 2013-12-6 10:41:11 | 显示全部楼层
你这样写出来的效果是什么,或者是说现在的问题是什么
 楼主| 发表于 2013-12-6 10:59:53 | 显示全部楼层
站长苏飞 发表于 2013-12-6 10:41
你这样写出来的效果是什么,或者是说现在的问题是什么

效果就是页面web加载的时候,就截图了。结果截图是空白的。
问题是:我想要页面加载完了再截图。页面加载完这个页面的绘图才画完。截图的时候就是截出画出的图!
谢了!
发表于 2013-12-6 11:03:29 | 显示全部楼层
写个JS在Load事件时调用,并设置3秒后执行应该没问题
 楼主| 发表于 2013-12-6 11:12:16 | 显示全部楼层
站长苏飞 发表于 2013-12-6 11:03
写个JS在Load事件时调用,并设置3秒后执行应该没问题

老大,如何编写,js不会。截图函数为Cutpicture().{:soso_e121:}
发表于 2013-12-6 11:30:38 | 显示全部楼层
不会百度下吧,一下子说不清楚,用ajax调用这个后台方法
 楼主| 发表于 2013-12-10 10:23:49 | 显示全部楼层
站长苏飞 发表于 2013-12-6 11:30
不会百度下吧,一下子说不清楚,用ajax调用这个后台方法

[C#] 纯文本查看 复制代码
<script>
      function run() {
          alert('延时1秒')    }
      window.onload = function () {
          setTimeout('run()', 1000)
      }
      $(document).ready(function () {
          $.ajax
        ({
            type: "GET",
            url: "CutPicture.aspx/CutPictureImg",
            beforeSend: function () {
                alert('正在加载');
            },
            success: function (data) {
                alert('加载完成');
            }
        });
      });
</script>

有两个页面一个是画图页面graphic.aspx,上面的代码放在里头。
另一个页面是CutPicture.aspx,里头有CutPictureImg方法,不知道我这样放对不对。谢谢!运行没有效果。哪里有问题呢?麻烦老大指点。
您需要登录后才可以回帖 登录 | 马上注册

本版积分规则

QQ|手机版|小黑屋|手机版|联系我们|关于我们|广告合作|苏飞论坛 ( 豫ICP备18043678号-2)

GMT+8, 2024-11-23 17:20

© 2014-2021

快速回复 返回顶部 返回列表