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

自定义一个截图函数,

         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
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值