无法获取窗口 C++ 的像素颜色
cant get pixel color of window c++
im 初学者使用 Windows.h 库并从 Windows 等获取信息。 我写了一个代码来查找任何窗口的像素颜色。我不确定我出了什么问题.
#include <iostream>
#include <windows.h>
using namespace std;
COLORREF centerColor;
POINT cent;
int main()
{
HWND hd = FindWindow(NULL, L"Untitled - Notepad");
HDC hdc_ = GetDC(hd);
cent.x = 0;
cent.y = 0;
centerColor = GetPixel(hdc_, cent.x, cent.y);
cout << centerColor;
}
你的代码可能正在工作(假设你有正确的窗口名称格式(;只是你可能不理解COLORREF
对象的格式。试试这个:
#include <iostream>
#include <windows.h>
using namespace std;
COLORREF centerColor;
POINT cent;
int main()
{
HWND hd = FindWindow(NULL, L"Untitled - Notepad");
// HWND hd = FindWindow(NULL, "Untitled - Notepad"); // Use this version if you are NOT using a Unicode build!
HDC hdc_ = GetDC(hd);
cent.x = 0;
cent.y = 0;
centerColor = GetPixel(hdc_, cent.x, cent.y);
// cout << centerColor;
cout << int(GetRValue(centerColor)) << " " << int(GetGValue(centerColor)) << " " << int(GetBValue(centerColor)) << endl;
ReleaseDC(hd, hdc_); // You should call this when you've finised with the DC!
}
这显示了像素颜色的三个 R/G/B 值(255 255 255 为白色(。
编辑:试试吧,看看你是否得到255 255 255
- 然后在记事本中输入一些文本并选择该文本,然后再次运行你的程序 - 应该给出不同的颜色!
它对我有用!
相关文章:
- 如何在24位SDL_Surface上设置像素的颜色
- 访问和更改基于另一个图像的像素颜色-opencv c++
- 无法获取窗口 C++ 的像素颜色
- 如何使用stb_image将像素颜色数据写入 BMP 图像文件?
- 从SDL_Texture访问像素颜色
- 结构像素颜色值
- 将OpenCV中的像素颜色映射到预定的颜色列表中
- magick 获得像素颜色.PixelPacket似乎不再存在了
- 在数组中设置像素颜色
- 在 openCV 中更改单个像素颜色
- 获取图像的像素颜色
- 使用 BMP 作为高度图.如何访问像素颜色以设置高度
- 以最快的方式获取像素颜色
- glsl-获取像素颜色[像素着色器]
- 如何访问位图中的像素颜色
- 快板定义像素颜色
- 使用像素颜色的人工神经网络
- 使用magick++获取像素颜色
- FreeImage:获取像素颜色
- 从指定坐标[x, y]处的位图数据获取像素颜色