gpt4 book ai didi

c - HDC 到 HDC for HDC

转载 作者:行者123 更新时间:2023-11-30 19:40:45 24 4
gpt4 key购买 nike

我想将 hdc blit 到另一个 hdc,并且该 hdc 将被 blit 到包含“BeginPaint”的 hdc。但问题出现了,什么也没有画出来。

这是代码,谢谢

HDC hdcMem3 = CreateCompatibleDC(NULL);


SelectObject(hdcMem3, Picture);

BITMAP bitmap;
GetObject(Picture, sizeof(bitmap), &bitmap);


HDC hdcMem2 = CreateCompatibleDC(NULL);
BitBlt(hdcMem2, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem3, 0, 0, SRCCOPY);
DeleteDC(hdcMem3);
BitBlt(hdcMem, 0, 0, bitmap.bmWidth, bitmap.bmHeight, hdcMem2, 0, 0, SRCCOPY);
DeleteDC(hdcMem2);

最佳答案

CreateCompatibleDC 使用 1 像素单色位图创 build 备上下文。

在您的示例中,hdcMem3 引用的设备上下文具有真实的位图,但 hdcMem2 引用的 DC 仅具有 1 像素单色位图。当您从 hdcMem3 传输到 hdcMem2 时,您可能最终会得到 1 个黑色像素。

您需要创建一个内存位图以选择到hdcMem2。我假设您最终会在窗口中显示它。假设您有一个名为 hdcWindow 的窗口设备上下文。

// Create a memory bitmap that's compatible with the window (screen) and
// the same size as Picture.
hbmpMem2 = CreateCompatibleBitmap(hdcWindow, bitmap.bmWidth, bitmap.bmHeight);
hbmpOld2 = SelectObject(hdcMem2, hbmpMem2);

现在,当您对 hdcMem2 进行操作时,它将绘制为真实的位图。

使用完 hdcMem2 后,您需要首先处理 hbmpMem2:

SelectObject(hdcMem2, hbmpOld2);
DeleteObject(hbmpMem2);
DestroyDC(hdcMem2);

关于c - HDC 到 HDC for HDC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34979414/

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