如何获取窗口客户区每个像素的 RGB 值数组

发布于 2024-12-07 08:54:23 字数 36 浏览 0 评论 0原文

有没有办法使用 gdi 接收窗口客户区中每个像素的颜色值?

Is there a way to receive the colour values for each pixel in the client area of a window, with gdi?

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

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

发布评论

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

评论(1

生寂 2024-12-14 08:54:23

正如@JerryCoffin 的评论中所指出的。下面是一个简单的示例

hDC = GetDC(hwnd);
hBitmap = CreateCompatibleBitmap(hDC, width, height);
hMemDC = CreateCompatibleDC(hDC);
hOld = SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0, width, height, hDC, x, y, SRCCOPY);

// Clean up
DeleteDC(hMemDC);
ReleaseDC(hwnd, hDC);

您应该在内存 DC 中选择一个位图对象,您可以使用 GetPixel GDI 函数,然后您还可以使用 GetRValue()GetGValue() 提取颜色值和 GetBValue() 宏。

As noted in comment by @JerryCoffin. Here's a simple example

hDC = GetDC(hwnd);
hBitmap = CreateCompatibleBitmap(hDC, width, height);
hMemDC = CreateCompatibleDC(hDC);
hOld = SelectObject(hMemDC, hBitmap);
BitBlt(hMemDC, 0, 0, width, height, hDC, x, y, SRCCOPY);

// Clean up
DeleteDC(hMemDC);
ReleaseDC(hwnd, hDC);

You should have a bitmap object selected into memory DC for which you can use GetPixel GDI function and then you can also extract the color values using GetRValue() , GetGValue() , and GetBValue() macros.

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