gpt4 book ai didi

c++ - 将一个 DeviceContext 的内容复制到另一个 DeviceContext

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

我从来没有做过任何 GDI 编程,尽管在黑暗中拍了几张照片并搜索了文档,但我还没有找到将一个 DC 的内容复制到另一个 DC 的正确方法。

我现在的代码如下。我不明白为什么它不起作用(创建后窗口仍然空白)。

SIZE srcSize;
// ... Get size of source DC

HDC destDC = ...; // from GetDC(myWindow), myWindow was
// sized before this to properly contain source
HDC sourceDC = ...;

HBITMAP buffer = CreateCompatibleBitmap(sourceDC, srcSize.cx, srcSize.cy);
HGDIOBJ oldObj = SelectObject(destDC, buffer);
BitBlt(destDC, 0, 0, srcSize.cx, srcSize.cy, sourceDC, 0, 0, SRCCOPY);
SelectObject(destDC, oldObj);
DeleteObject(buffer);

//... ReleaseDC()s here

正确的做法是什么?

最佳答案

从一个 DC 复制到另一个 DC 所需的唯一东西是 BitBlt。有效的代码如下。

SIZE srcSize;
// ... Get size of source DC

HDC destDC = ...; // from GetDC(myWindow), myWindow was
// sized before this to properly contain source
HDC sourceDC = ...;

BitBlt(destDC, 0, 0, srcSize.cx, srcSize.cy, sourceDC, 0, 0, SRCCOPY);
//... ReleaseDC()s here

关于c++ - 将一个 DeviceContext 的内容复制到另一个 DeviceContext,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10407500/

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