在 Windows 7 上的图像捕获中,窗口的最顶部被切断

发布于 2024-10-17 04:32:00 字数 1150 浏览 4 评论 0原文

我们的应用程序中有一些代码可以捕获窗口的图像并将其保存到 PNG 文件并将其复制到剪贴板(C++ API 代码)。

在 Windows XP 上完美运行。它也适用于 Windows 7,只不过它看起来好像图像的顶部几行像素线已被截断,就好像捕获的区域不包括窗口的顶部几行一样。然而我们的代码清楚地从图像的顶部复制,如下所示。

在此处输入图像描述

(在 Windows XP 上,您会在右侧看到完整的 X 以及窗口的顶部边框)

这是 Windows 7 上的某种航空效果或其他显示效果吗?还是有办法弥补这一点?或者我们的代码中的某些内容可能会导致这种情况?

当然,我们可以确定窗口区域并从客户端窗口捕获它,并捕获更高的几行,但是有多少行,这似乎是任意的。

这里一定存在一些根本性的缺陷或问题吗?

我们的代码大致如下:

RECT wndRect;
GetWindowRect(hwnd, &wndRect);
int Width = wndRect.right - wndRect.left;
int Height = wndRect.bottom - wndRect.top;
BYTE *pBits = 0;
BITMAPINFO bmpinfo = {sizeof(BITMAPINFO)};
bmpinfo.bmiHeader.biWidth = Width;
bmpinfo.bmiHeader.biHeight = Height;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = 24;
bmpinfo.bmiHeader.biCompression = BI_RGB;
HBITMAP hBmp = CreateDIBSection(NULL, &bmpinfo, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);
HDC hWndDC = GetWindowDC(hwnd);
HDC hDC = CreateCompatibleDC(hWndDC);
HBITMAP hOldBmp = (HBITMAP)SelectObject(hDC, hBmp);
BitBlt(hDC, 0, 0, Width, Height, hWndDC, 0, 0, SRCCOPY);

We have some code inside our application that captures an image of a window and saves it to a PNG file and copies it to the clipboard (C++ API code).

Works perfectly on Windows XP. It also works on Windows 7, except that it looks as if the top few pixel lines of the image have been chopped off, as if the area that was captured did not include the top few lines of the window. Yet our code clearly copies from the top of the image, shown below.

enter image description here

(On Windows XP you see the full X on the right hand side plus the top border of the Window)

Is this some aero or other display effect on Windows 7, or is there a way to compensate for this?Or could something in our code possibly be causing this?

Sure, we can determine the window area and capture it from the client window, and capture a few lines higher up, but how may lines, and that seems arbitrary.

There must be some fundamental flaw or issue here?

Our code is roughly as follows:

RECT wndRect;
GetWindowRect(hwnd, &wndRect);
int Width = wndRect.right - wndRect.left;
int Height = wndRect.bottom - wndRect.top;
BYTE *pBits = 0;
BITMAPINFO bmpinfo = {sizeof(BITMAPINFO)};
bmpinfo.bmiHeader.biWidth = Width;
bmpinfo.bmiHeader.biHeight = Height;
bmpinfo.bmiHeader.biPlanes = 1;
bmpinfo.bmiHeader.biBitCount = 24;
bmpinfo.bmiHeader.biCompression = BI_RGB;
HBITMAP hBmp = CreateDIBSection(NULL, &bmpinfo, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);
HDC hWndDC = GetWindowDC(hwnd);
HDC hDC = CreateCompatibleDC(hWndDC);
HBITMAP hOldBmp = (HBITMAP)SelectObject(hDC, hBmp);
BitBlt(hDC, 0, 0, Width, Height, hWndDC, 0, 0, SRCCOPY);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2024-10-24 04:32:00

我读过一次,RECT 坐标会切断底部像素,但从未听说过顶部像素...可能有一些 api 调用在某个地方来获取窗口装饰的大小或其他什么。

GetDCEx 也可能有帮助。

I read once that the RECT coords cut off the bottom pixel but never heard of the top pixel...There may be some api call somewhere to get the size of the window decoration or what not.

GetDCEx might help as well.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文