gpt4 book ai didi

java - 获取开始菜单的截图

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:29:57 25 4
gpt4 key购买 nike

我正在使用 bitblt 来捕获窗口。如果启用 aero 主题,则捕获图像的背景为黑色。如果我禁用 DWM 并捕获窗口,则捕获的图像非常好。

这是我的部分代码。

HDC hdcMemDC = GDI32.INSTANCE.CreateCompatibleDC(desktopDC);
HDC windowDC = User32.INSTANCE.GetDC(window);

HWND window= User32Extra.INSTANCE.FindWindow(null, "Start menu");

GDI32Extra.INSTANCE.BitBlt(hdcMemDC, 0, 0, width, height, desktopDC, 0, 0, WinGDIExtra.SRCCOPY );
GDI32Extra.INSTANCE.BitBlt(hdcMemDC,windowBounds.left, windowBounds.top, windowWidth, windowHeight, windowDC, windowBounds.left+windowBounds1.right-windowBounds.right+(windowExtraGap/2), windowBounds.top+windowBounds1.bottom-windowBounds.bottom+(windowExtraGap/2), WinGDIExtra.SRCCOPY);

enter image description here

如何截取合适背景的开始菜单?

有没有其他方法可以得到正确的气动窗口图像?

最佳答案

使用桌面DC并切到窗口

RECT rc, rc2;
GetClientRect(hWnd, &rc);
GetWindowRect(hWnd, &rc2);
int width = rc2.right - rc2.left;
int height = rc2.bottom - rc2.top;
HDC hdcScreen = GetDC(NULL); //!!!! Get desktop DC

HDC hBmpFileDC = CreateCompatibleDC(hdcScreen);
HBITMAP hBmpFileBitmap = CreateCompatibleBitmap(hdcScreen, width, height);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBmpFileDC, hBmpFileBitmap);
BitBlt(hBmpFileDC, 0, 0, width, height, hdcScreen, rc2.left, rc2.top, SRCCOPY | CAPTUREBLT);
HGDIOBJ prev = SelectObject(hBmpFileDC, hOldBitmap);

SaveBitmap(szLogFilename, hBmpFileBitmap);

DeleteDC(hBmpFileDC);
DeleteObject(hBmpFileBitmap);

另一种变体

RECT rc;
GetClientRect(hWnd, &rc);

int width = rc.right - rc.left;
int height = rc.bottom - rc.top;

HDC hdcScreen = GetDC(hWnd);
////////////////////////////
PrintWindow(hWnd, hdcScreen, 0);
PrintWindow(hWnd, hdcScreen, PW_CLIENTONLY);
////////////////////////////
HDC hBmpFileDC = CreateCompatibleDC(hdcScreen);
HBITMAP hBmpFileBitmap = CreateCompatibleBitmap(hdcScreen, width, height);
HBITMAP hOldBitmap = (HBITMAP)SelectObject(hBmpFileDC, hBmpFileBitmap);
BitBlt(hBmpFileDC, 0, 0, width, height, hdcScreen, 0, 0, SRCCOPY | CAPTUREBLT);
HGDIOBJ prev = SelectObject(hBmpFileDC, hOldBitmap);

SaveBitmap(szLogFilename, hBmpFileBitmap);

DeleteDC(hBmpFileDC);
DeleteObject(hBmpFileBitmap);

在调用任何捕获方法之前,我调用 PrintWindow。它作为窗口重绘自身。因此,屏幕截图将具有正确的图片。两次调用 PrintWindow 得到的最稳定的结果。

关于java - 获取开始菜单的截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31261999/

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