小编Ase*_*jix的帖子

113
推荐指数
7
解决办法
7万
查看次数

如果我不调用dispose()会发生什么?

    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);
    }
Run Code Online (Sandbox Code Playgroud)

我正在使用此代码捕获我的计算机屏幕.

但今天我发现有一个名为Bitmap.Dispose()的方法.

什么时候调用Dispose()有什么区别?代码运行至关重要吗?

c# dispose bitmap

5
推荐指数
2
解决办法
4400
查看次数

标签 统计

angular ×1

bitmap ×1

c# ×1

debugging ×1

dispose ×1

visual-studio-code ×1

webpack ×1