【发布时间】:2015-09-04 11:43:01
【问题描述】:
public void screenShot(string path)
{
var bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
var gfxScreenshot = Graphics.FromImage(bmpScreenshot);
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
bmpScreenshot.Save(path, ImageFormat.Png);
}
我正在使用此代码来捕获我的计算机屏幕。
但是今天我发现有一个方法叫Bitmap.Dispose()。
何时调用 Dispose() 有什么区别?代码运行是否重要?
【问题讨论】:
-
了解“垃圾收集器”
-
许多 .NET 程序员从未在他们的代码中使用过 Dispose()。 Bitmap 类是一个很少有好结果的 .NET 类。他们倾向于为像素数据占用大量的非托管内存。当您创建太多屏幕截图时 Kaboom。