Im trying to check if there pixel with white (#FFFFFF) or green (#00FF00) color of the screen's region. Usualy its 500x500 (250'000 pixels). Im checking every 5th pixel:

x := iMRXDef; // starting region coordinates
y := iMRYDef;
while DoMR do // global boolean variable
  begin
    inc(x, 4);
    if x >= iMRXMax then  // ending region coordinates
      if y < iMRYMax then
        begin
          inc(y, 4);
          x := iMRXDef;
        end
      else
        begin
          x := iMRXDef;
          y := iMRYDef;
        end;
    DC := GetDC(0);
    ColorValue := GetPixel(DC, X, Y);
    ReleaseDC(0, DC);
    if (ColorValue = iMRColorV) or (ColorValue = iMRColorV2) then
      begin
        performClick(X, Y); // clicking by SendInput.
        x := x + 30; // skip some area
        y := y + 20;
        sleep(500);
      end;
  end;

For some reason, on win8 running my programm takes a lot of time (couple of minutes) whilst on win7 its about couple of seconds. What causes this difference?

有帮助吗?

解决方案

Take a screenshot of the area you're interested in and read the pixels from that bitmap. Then access the pixels from the scanlines property of the bitmap if possible. Should be a lot faster.

GetPixel is generally not a fast function. And some Windows 8 screen dpi changes can also slow down graphics quite a lot. So it is hard to tell what is slowing down your code. You'd have to profile your code if you want to know which part is so much slower on this Win8 PC.

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