现在,我使用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来说是如此新,他们对我并不为我做很多事情。谢谢!

有帮助吗?

解决方案

您可能想要:

  • CreateCompatibledc
  • CreateCompatibleBitMap
  • selectObject,保存原始位图
  • Bitblt
  • getDibits
  • selectObject,放回原始位图
  • DeleteBitMap
  • DELETEDC

如果您定期这样做,那么您应该只做前三个步骤,重复一次 BitBltGetDIBits, ,以及您的程序完成的最后三个。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top