gpt4 book ai didi

c++ - HBITMAP 内存泄漏

转载 作者:太空宇宙 更新时间:2023-11-04 16:30:10 24 4
gpt4 key购买 nike

无论我多么努力地寻找和尝试,我都找不到这段代码泄漏的原因。实际上,我不确定泄漏,但每次使用这段代码时 GDI 对象的数量都会增加。

HBITMAP hBmp;
hBmp = CreateDIBitmap(dc, &stBmpIH, CBM_INIT, m_pBitmapData, m_pBitmapInfo, DIB_RGB_COLORS) ;

Bitmap *pBMP = NULL;
HPALETTE hPal = NULL;
Color col = 0;

pBMP = Bitmap::FromHBITMAP(hBmp, hPal);

if (m_bFlip)
{
pBMP->RotateFlip( Rotate90FlipXY );
pBMP->GetHBITMAP(col,&hBmp);
m_bFlip = FALSE;
}
else
{
pBMP->RotateFlip( RotateNoneFlipX );
pBMP->GetHBITMAP(col,&hBmp);
}

delete pBMP;

我用工具检查了 GDI 对象,发现 HBITMAP hBmp 是泄漏的对象。我应该如何删除它?

DeleteObject 无效。

谢谢

最佳答案

来自FromHBITMAP documentation :

You are responsible for deleting the GDI bitmap and the GDI palette. However, you should not delete the GDI bitmap or the GDI palette until after the GDI+ Bitmap object is deleted or goes out of scope.

仅仅删除Bitmap对象是不够的,之后还需要在hBmp上调用DeleteObject

关于c++ - HBITMAP 内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7957730/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com