我有一个简单的循环,可以使用CopyFromScreen创建位图:
static void Main(string[] args)
{
while(true)
{
Bitmap bitmap = new Bitmap(makeScreenshot());
Thread.Sleep(1000);
bitmap.Dispose();
}
}
public static Bitmap makeScreenshot()
{
Bitmap screenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
Graphics gfxScreenshot = Graphics.FromImage(screenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
gfxScreenshot.Dispose();
return screenshot;
}
但是我可以看到每个循环在内存中的增加?如果我将新的位图修改为此:
Bitmap bitmap = new Bitmap(1024,768);
处置似乎按预期方式工作,那么makeScreenshot是否以某种方式保存对象?
谢谢