int counter = 0;
private void timer1_Tick(object sender, EventArgs e)
{
counter++;
using (Bitmap bmp =
new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height))
{
pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);
bmp.Save(@"e:\screenshots\" + "screenshot" + counter.ToString("D6") + ".png"
, System.Drawing.Imaging.ImageFormat.Png);
}
if (counter == 1200)
timer1.Stop();
}
我可以在硬盘上看到前180张图片。 但后来它显示了异常。
System.ArgumentException occurred
HResult=-2147024809
Message=Parameter is not valid.
Source=System.Drawing
StackTrace:
at System.Drawing.Graphics.GetHdc()
at System.Windows.Forms.Control.DrawToBitmap(Bitmap bitmap, Rectangle targetBounds)
at Youtube_Manager.Elgato_Video_Capture.timer1_Tick(Object sender, EventArgs e) in d:\C-Sharp\Youtube-Manager\Youtube-Manager\Youtube-Manager\Elgato_Video_Capture.cs:line 191
InnerException:
不确定为什么它会在180张图像之后而不是之前抛出异常。
第191行是:
pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);