title: Find image on screen
body: <p>I wonder how to solve this problem. I want to check every X seconds if the screen contains an image (for example a red dot) and if so return True. I am very familiar with Python, and there are some easy solutions there. But I haven't found a similar solution yet.</p>
  
  <p>What I basically want to do is:</p>
  
  <ol>
  <li>Take a screenshot</li>
  <li>Locate image X on the screenshot</li>
  <li>Return bool</li>
  </ol>
  
  <p>Looked into OpenCV and would be possible to solve it that way, but might be a bit overextending. I was thinking about getPixel to loop over all the pixels in the screen. But it's extremely slow. </p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;iostream&gt;
  
  using namespace std;
  
  int main()
  {
      HWND runelite = GetForegroundWindow();
      HMONITOR monitor = MonitorFromWindow(runelite, MONITOR_DEFAULTTONEAREST);
      MONITORINFO info;
      info.cbSize = sizeof(MONITORINFO);
      GetMonitorInfo(monitor, &amp;info);
      int monitor_width = info.rcMonitor.right - info.rcMonitor.left;
      int monitor_height = info.rcMonitor.bottom - info.rcMonitor.top;
  
      int r, g, b;
  
      HDC screenshot = GetDC(NULL); 
  
      for (int i = 0; i &lt; monitor_height; i++) {
          for (int j = 0; j &lt; monitor_width; j++) {
              DWORD color = GetPixel(screenshot, j, i);
              cout &lt;&lt; "Scanning -&gt; X: " &lt;&lt; j &lt;&lt; " Y: " &lt;&lt; i &lt;&lt; endl;
              r = GetRValue(color);
              g = GetGValue(color);
              b = GetBValue(color);
              if (r == 0 &amp;&amp; g == 0 &amp;&amp; b == 0) {
                  cout &lt;&lt; "Button found by color!" &lt;&lt; endl;
                  goto end;
              }
          }
      }
  
      end:
      ReleaseDC(NULL, screenshot);
      return 0;
  }
  </code></pre>