title: C++ Pixel Grabber wrong RGB values
body: <p>my pixel grabber (I modified it from online source) But the RGB values are off.. Could someone take a look at this, and maybe fix it.</p>
  
  <p>I'm trying to grab all pixels from the screen and turn values into RGB as fast as possible.</p>
  
  <pre><code>#include "iostream"
  #include &lt;Windows.h&gt;
  using namespace std;
  
  HDC hdc, hdcTemp;
  int x, y;
  
  
  void PixelFunction();   // Get the pixel rgb function
  
  int main()
  {
      PixelFunction();
      ReleaseDC(HWND_DESKTOP, hdc);
      cout&lt;&lt;"done";
      getchar();
      return 0;
  }
  
  
  void PixelFunction()
  {
      BYTE* bitPointer;
      int red, green, blue, alpha;
  
      hdc = GetDC(HWND_DESKTOP);
      int MAX_WIDTH = GetDeviceCaps(hdc, HORZRES);
      int MAX_HEIGHT = GetDeviceCaps(hdc, VERTRES);
  
      hdcTemp = CreateCompatibleDC(hdc);
      BITMAPINFO bitmap;
      bitmap.bmiHeader.biSize = sizeof(bitmap.bmiHeader);
      bitmap.bmiHeader.biWidth = MAX_WIDTH;
      bitmap.bmiHeader.biHeight = MAX_HEIGHT;
      bitmap.bmiHeader.biPlanes = 1;
      bitmap.bmiHeader.biBitCount = 32;
      bitmap.bmiHeader.biCompression = BI_RGB;
      bitmap.bmiHeader.biSizeImage = MAX_WIDTH * 4 * MAX_HEIGHT;
      bitmap.bmiHeader.biClrUsed = 0;
      bitmap.bmiHeader.biClrImportant = 0;
      HBITMAP hBitmap2 = CreateDIBSection(hdcTemp, &amp;bitmap, DIB_RGB_COLORS, (void**)(&amp;bitPointer), NULL, NULL);
      SelectObject(hdcTemp, hBitmap2);
      BitBlt(hdcTemp, 0, 0, MAX_WIDTH, MAX_HEIGHT, hdc, 0, 0, SRCCOPY);
      for (int i=0; i&lt;MAX_HEIGHT; i ++)
      {
          for (int ii=0; ii&lt;MAX_WIDTH; ii++)
          {
  
              {
                  blue = (int)bitPointer[ii];
                  green = (int)bitPointer[ii+1];
                  red = (int)bitPointer[ii+2];
                  alpha = (int)bitPointer[ii+3];
  
                  cout &lt;&lt; "Red " &lt;&lt; red &lt;&lt; ".\n";
                  cout &lt;&lt; "Green " &lt;&lt; green &lt;&lt; ".\n";
                  cout &lt;&lt; "Blue " &lt;&lt; blue &lt;&lt; ".\n";
                  SetCursorPos(ii, i);
  
                  Sleep(500);
              }
          }
  
      }
  
  
  
  
  
  }
  </code></pre>