title: CreateDIBSection to get uint8_t[] of portion of screen
body: <p>I am trying to get a uint8_t[] of a portion of the screen. The xy coordinates of the top left is 2,3 and of bottom right is 17,18.</p>
  
  <p>This is the top 30x30 pixels of my screen with regular screenshot and photoshop crop:</p>
  
  <p><img src="https://i.imgur.com/z8CQ57W.png" alt=""></p>
  
  <p>And this is what 2,3 to 17,18 screenshot should look like via regular screenshot and Photoshop crop:</p>
  
  <p><img src="https://i.imgur.com/rHfF3be.png" alt=""></p>
  
  <p>This is what I am getting as a result of my code:</p>
  
  <p><img src="https://i.imgur.com/VUWfAF5.png" alt=""></p>
  
  <p>My code is in js-ctypes but there is no ctypes errors. This is a winapi thing. So I didn't tag this with ctypes as they would be confused. This is the simplified code I am using, the error checks etc have been removed:</p>
  
  <pre><code>c1 = {x:2, y:3} // top left corner
  c2 = {x:17, y:18} // bottom right corner
  
  CreateDC('DISPLAY', null, null, null);
  nBPP = GetDeviceCaps(hdcScreen, BITSPIXEL);
  
  w = c2.x - c1.x; // width = 15
  h = c2.y - c1.y; // height = 15
  
  hdcMemoryDC = CreateCompatibleDC(hdcScreen);
  
  bmi = BITMAPINFO();
  bmi.bmiHeader.biSize = BITMAPINFOHEADER.size;
  bmi.bmiHeader.biWidth = w;
  bmi.bmiHeader.biHeight = -1 * h;
  bmiHeader.biPlanes = 1;
  bmi.bmiHeader.biBitCount = nBPP; // nBPP is 32
  bmi.bmiHeader.biCompression = BI_RGB;
  
  hbmp = CreateDIBSection(hdcScreen, &amp;bmi, DIB_RGB_COLORS, (void**)&amp;pixelBuffer, null, 0);
  
  SelectObject(hdcMemoryDC, hbmp);
  BitBlt(hdcMemoryDC, 0, 0, w, h, hdcScreen, c1.x, c1.y, SRCCOPY);
  </code></pre>
  
  <p>Why portion of screen bits come out wrong? If I do a full screen shot it works fine.</p>