现在我正在使用 GetPixel() 从桌面检索大约 64 个像素以获得它们的颜色。我读到 GetPixel() 很慢,但认为这对几个像素无关紧要,但每次运行例程都需要 1.5 秒。在做了一些研究之后,我得出的结论是 bitblt 似乎是我正在寻找的东西。我想要做的是抓取桌面的定义区域(包括所有窗口),然后在给定的偏移量处抓取像素颜色。这就是我现在正在做的事情:
for (y=0;y<=7;y++) {
for (x=0;x<=7;x++) {
//gameScreen is a struct containing the offset from the top left of the monitor
//to the area of the screen I need
grid[y][x]=getColor(gameScreen.x+((x*40)+20),gameScreen.y+((y*40)+20));
}
}
int getColor(int x, int y) {
//create new point at given coordinates
POINT point;
point.x=x;
point.y=y;
//convert to logical points
DPtoLP(desktopDC,&point,2);
//get pixel color
//desktopDC is an HDC from GetWindowDC(GetDesktopWindow())
int pixel=GetPixel(desktopDC,point.x,point.y);
return pixel;
}
我找到了大量的教程和文档,但是对于 Windows API 来说太新了,它们对我来说并没有做太多。谢谢!