Advertisement
keverman

screenshoting

Aug 22nd, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. bool update(std::vector<std::vector<col>> &pix)
  2. {
  3.     uint h = pix.size(), w = pix.front().size();
  4.  
  5.     HDC hdcSource = GetDC(NULL);
  6.     HDC hdcMemory = CreateCompatibleDC(hdcSource);
  7.  
  8.     HBITMAP hBitmap = CreateCompatibleBitmap(hdcSource, w, h);
  9.     SelectObject(hdcMemory, hBitmap);
  10.  
  11.     BitBlt(hdcMemory, 0, 0, w, h, hdcSource, sc.lCor.x, sc.lCor.y, SRCCOPY);
  12.  
  13.     BITMAPINFO bmpinfo = { 0 };
  14.     bmpinfo.bmiHeader.biSize = sizeof(bmpinfo.bmiHeader);
  15.  
  16.     if (!GetDIBits(hdcMemory, hBitmap, 0, 0, NULL, &bmpinfo, DIB_RGB_COLORS))
  17.     {
  18.         return false;
  19.     }
  20.  
  21.     BYTE *pixelMap = new BYTE[bmpinfo.bmiHeader.biSizeImage];
  22.  
  23.     bmpinfo.bmiHeader.biBitCount = 32;
  24.     bmpinfo.bmiHeader.biCompression = BI_RGB;
  25.     bmpinfo.bmiHeader.biHeight = -bmpinfo.bmiHeader.biHeight;
  26.  
  27.     if (!GetDIBits(hdcMemory, hBitmap, 0, h, pixelMap, &bmpinfo, DIB_RGB_COLORS))
  28.     {
  29.         return false;
  30.     }
  31.  
  32.     ReleaseDC(NULL, hdcSource);
  33.     DeleteDC(hdcMemory);
  34.     DeleteObject(hBitmap);
  35.  
  36.     char* cPixel = (char*)pixelMap;
  37.  
  38.     for (uint y = 0; y < h; y++)
  39.     {
  40.         for (uint x = 0; x < w; x++)
  41.         {
  42.             pix[y][x] = col(cPixel[2] & 0xFF, cPixel[1] & 0xFF, cPixel[0] & 0xFF);
  43.             cPixel += 4;
  44.         }
  45.     }
  46.  
  47.     delete[] pixelMap;
  48.  
  49.     return true;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement