【发布时间】:2013-05-29 12:29:24
【问题描述】:
我用 C# 制作了一个应用程序,它将连续执行屏幕捕获并使用计时器将其显示在 PictureBox 中。运行几秒钟后,出现了 ArgumentException。
下面是出现 ArgumentException 的代码和行
private void timer1_Tick(object sender, EventArgs e)
{
Rectangle bounds = Screen.GetBounds(Point.Empty);
Graphics graphics;
Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height);
using (graphics = Graphics.FromImage(bitmap))
{
graphics.CopyFromScreen(0, 0, 0, 0, new Size(bounds.Width , bounds.Height )); // ArgumentException
pictureBox1.Image = bitmap;
pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
}
}
除此之外,我注意到在运行该应用几秒钟后,Windows 会出现一条提示内存不足的警报。
有解决这个问题的技巧吗?
【问题讨论】:
-
@GSerg 处理后,PictureBox 无法再显示图片了。