gpt4 book ai didi

C++双缓冲区和内存

转载 作者:行者123 更新时间:2023-11-28 08:27:19 27 4
gpt4 key购买 nike

好的,我的双缓冲区工作正常,但它似乎占用了大量内存。

我知道双缓冲区应该存储我正在绘制的椭圆的拷贝,而不是在屏幕上绘制它,但之后它会删除拷贝并制作新拷贝,但它似乎并没有删除它这是我的代码

hdc=GetDC(hWnd);
HDC memDC=CreateCompatibleDC(hdc);
HBITMAP hMemMap=CreateCompatibleBitmap(hdc, 300, 300);
HBITMAP hOldMap=(HBITMAP)SelectObject(memDC, hMemMap);

// Drawing
Graphics draw(memDC);
draw.FillRectangle(&green, 0, 0, 300, 25);
Font font(&fontfamily, 14, 0, UnitPixel);
PointF p1(180.0f, 4.0f);
PointF p2(30.0f, 4.0f);
draw.DrawString(level, -1, &font, p2, &blue);
draw.DrawString(str, -1, &font, p1, &blue);
draw.FillEllipse(&red, ball1.Ex, ball1.Ey, 25, 25);
draw.FillEllipse(&red, ball2.Ex, ball2.Ey, 25, 25);
draw.FillEllipse(&red, ball3.Ex, ball3.Ey, 25, 25);
draw.FillEllipse(&red, ball4.Ex, ball4.Ey, 25, 25);
draw.FillEllipse(&red, ball5.Ex, ball5.Ey, 25, 25);
draw.FillEllipse(&red, ball6.Ex, ball6.Ey, 25, 25);
draw.FillEllipse(&red, ball7.Ex, ball7.Ey, 25, 25);
draw.FillEllipse(&red, ball8.Ex, ball8.Ey, 25, 25);
draw.FillEllipse(&red, ball9.Ex, ball9.Ey, 25, 25);
draw.FillEllipse(&red, ball10.Ex, ball10.Ey, 25, 25);
BitBlt(hdc, 0, 0, 300, 300, memDC, 0, 0, SRCCOPY);
SelectObject(memDC, hOldMap);
DeleteObject(hMemMap);
DeleteDC(memDC);

有什么想法吗?

最佳答案

您正在销毁所有对象,但不会销毁 DC。绘图后必须调用 ReleaseDC。

参见 MSDN :

After painting with a common device context, the ReleaseDC function must be called to release the device context.

关于C++双缓冲区和内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3506661/

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