位图未处理?

时间:2018-07-11 06:58:37

标签: c# bitmap

我有一个简单的循环,可以使用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是否以某种方式保存对象?

谢谢

0 个答案:

没有答案