C#实现定时全屏截图并且保存到预先设定好的文件夹中的代码示例

来源:互联网 发布:pes2017亨利捏脸数据 编辑:程序博客网 时间:2024/05/19 12:26

自定义一个截图函数,

         public static void Snap(int x, int y, int width, int height)
        {
            try
            {

                 //这段代码也可以实现截图
                //Image image = new Bitmap(width, height);
                //Graphics g = Graphics.FromImage(image);
                //g.CopyFromScreen(x, y, 0, 0, new System.Drawing.Size(width, height));
                //string hour = DateTime.Now.Minute.ToString();
                //string second = DateTime.Now.Second.ToString();
                //image.Save(ScreenshotPath + "\\" + hour + "_" + second + ".jpg");




                Bitmap image = new Bitmap(GetSystemMetrics(0), GetSystemMetrics(1));
                using (Graphics g = Graphics.FromImage(image))
                {
                    g.CopyFromScreen(0, 0, 0, 0, image.Size);
                    g.Dispose();
                    string hour = DateTime.Now.Minute.ToString();
                    string second = DateTime.Now.Second.ToString();
                    image.Save(“C:” + "\\" + hour + "_" + second + ".jpg");
                }
            }
            catch
            {


            }
        }


      然后在一个timerSrc_Tick 中调用自定义的截图函数,然后就会定时截图,保存到指定文件夹

        private void timerSrc_Tick(object sender, EventArgs e)
        {
            Help.Snap(0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
        }

截图并且保存到预先设定好的文件夹中的代码示例

0 0
原创粉丝点击