0

我一直在尝试使用存储在 HBITMAP 中的屏幕截图并将其输出为 PNG 图像。

但是,代码中似乎存在内存泄漏,因为内存似乎没有被正确释放。

void saveAsPNG(HBITMAP h)
{
CImage image;

if(_access(location, 0) == 0)
{
    unlink(location); //Delete the image if currently exists
}


image.Attach(h);

image.Save(location,Gdiplus::ImageFormatPNG);


h = image.Detach();


image.Destroy();
image.ReleaseGDIPlus();
}

此代码有效,但似乎没有清除内存。根据任务管理器中的私有内存集列,image.Destroy 根本不会影响内存,而 image.ReleaseGDIPlus 似乎会清理一些数据。HBITMAP 来自先前的函数,并在代码中的稍后位置被 GlobalFreed 与此函数分开。

是不是少了一行?

4

0 回答 0