1分钟后拍摄截图 [英] Taking Screenshot after 1 minute

查看:115
本文介绍了1分钟后拍摄截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个问题:



1。每隔1分钟,如何在按下键后每1分钟拍摄一次屏幕截图,例如:



  1. 10 :00:->键按下-> Img1

  2. 10:01:->键按下-> Img2

  3. 10:02:->键按下-> Img3


2。假设程序运行5-10分钟,如何迭代图像链

 字符串ImgPath = @ D :\ Img +迭代+ .bmp; 
位图btmp =新Bitmap(Screen.PrimaryScreen.Bounds.Width,Screen.PrimaryScreen.Bounds.Height);
Graphics g =图形。 FromImage(btmp);
g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,Screen.PrimaryScreen.Bounds.Y,0,0,btmp.Size,CopyPixelOperation.SourceCopy);




如果(按任意键)

如果(时差为1分钟)

btmp.Save(ImgPath,System.Drawing.Imaging.ImageFormat.Bmp);


如果有的话

谢谢!

解决方案

您要执行的是启动(或重新启动)秒表拍照。然后,每按一次键,您都会检查秒表是否已经运行了至少一分钟。如果有,请拍照并重置秒表。一般思路:

  //程序启动时开始计时。 
私人秒表_pictureTimer = Stopwatch.StartNew();

//在图片之间等待这么长时间
private readonly TimeSpan _pictureWaitTime = TimeSpan.FromMinutes(1.0);

//按下键时来到这里。
if(_pictureTimer.Elapsed> _pictureWaitTime)
{
//拍摄屏幕快照
//然后重置秒表
_pictureTimer.Restart();
}

如果要对图片编号,请保留每次更新的变量。程序启动时,将其初始化:

  private int _pictureNumber = 1; 

每当您拍照时,都将其递增。也就是说,重置秒表后,只需执行以下操作:

  _pictureNumber = pictureNumber + 1; 


I have two questions:

1. How can I take screenshot after every 1 min, when a key is pressed E.g.

  1. 10:00: -> key pressed -> Img1
  2. 10:01: -> key pressed -> Img2
  3. 10:02: -> key pressed -> Img3

2. How can I iterate the image chain assuming my program runs for 5-10 mins

  string ImgPath = @"D:\"Img" + iteration + ".bmp";
  Bitmap btmp = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
  Graphics g = Graphics.FromImage(btmp);
  g.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, btmp.Size, CopyPixelOperation.SourceCopy);

if (any key is pressed)
if (time difference is 1 min)
btmp.Save(ImgPath, System.Drawing.Imaging.ImageFormat.Bmp);

Also if there is a more better way to take screenshot please share here.

Thanks!

解决方案

What you want to do is start (or restart) a Stopwatch when you take a picture. Then, whenever a key is pressed, you check if the Stopwatch has been running for at least a minute. If it has, you take the picture and reset the stopwatch. The general idea:

// Start the clock when the program starts.
private Stopwatch _pictureTimer = Stopwatch.StartNew();

// Wait this long between pictures
private readonly TimeSpan _pictureWaitTime = TimeSpan.FromMinutes(1.0);

// Come here when key is pressed.
if (_pictureTimer.Elapsed > _pictureWaitTime)
{
    // take the screen shot
    // and then reset the stopwatch
    _pictureTimer.Restart();
}

If you want to number the pictures, keep a variable that you update every time. When the program starts, you initialize it:

private int _pictureNumber = 1;

And whenever you take a picture, you increment it. That is, after resetting the stopwatch, just do:

_pictureNumber = pictureNumber + 1;

这篇关于1分钟后拍摄截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆