Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool update(std::vector<std::vector<col>> &pix)
- {
- uint h = pix.size(), w = pix.front().size();
- HDC hdcSource = GetDC(NULL);
- HDC hdcMemory = CreateCompatibleDC(hdcSource);
- HBITMAP hBitmap = CreateCompatibleBitmap(hdcSource, w, h);
- SelectObject(hdcMemory, hBitmap);
- BitBlt(hdcMemory, 0, 0, w, h, hdcSource, sc.lCor.x, sc.lCor.y, SRCCOPY);
- BITMAPINFO bmpinfo = { 0 };
- bmpinfo.bmiHeader.biSize = sizeof(bmpinfo.bmiHeader);
- if (!GetDIBits(hdcMemory, hBitmap, 0, 0, NULL, &bmpinfo, DIB_RGB_COLORS))
- {
- return false;
- }
- BYTE *pixelMap = new BYTE[bmpinfo.bmiHeader.biSizeImage];
- bmpinfo.bmiHeader.biBitCount = 32;
- bmpinfo.bmiHeader.biCompression = BI_RGB;
- bmpinfo.bmiHeader.biHeight = -bmpinfo.bmiHeader.biHeight;
- if (!GetDIBits(hdcMemory, hBitmap, 0, h, pixelMap, &bmpinfo, DIB_RGB_COLORS))
- {
- return false;
- }
- ReleaseDC(NULL, hdcSource);
- DeleteDC(hdcMemory);
- DeleteObject(hBitmap);
- char* cPixel = (char*)pixelMap;
- for (uint y = 0; y < h; y++)
- {
- for (uint x = 0; x < w; x++)
- {
- pix[y][x] = col(cPixel[2] & 0xFF, cPixel[1] & 0xFF, cPixel[0] & 0xFF);
- cPixel += 4;
- }
- }
- delete[] pixelMap;
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement