问题描述
我有两个问题:
1。每隔1分钟,如何在按下键后每1分钟拍摄一次屏幕截图,例如:
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);
如果有的话
谢谢!
您要执行的是启动(或重新启动)拍照。然后,每按一次键,您都会检查秒表是否已经运行了至少一分钟。如果有,请拍照并重置秒表。一般思路:
//程序启动时开始计时。
私人秒表_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.
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);
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分钟后拍摄截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!