Hello, I am trying to pull out an array of pixels from the shared bitmap (completely filled with RGB(0,0,255) ) via GetDIBits , but some other colors are given. And when you try to make changes to an array, it crashes altogether. What's wrong?
case WM_PAINT: { PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd, &ps); HBRUSH hb = CreateSolidBrush(RGB(0, 0, 255)); HDC hdcc = CreateCompatibleDC(hdc); HBITMAP bm = CreateCompatibleBitmap(hdc, r.right, r.bottom); SelectObject(hdcc, bm); SelectObject(hdcc, hb); Rectangle(hdcc, 0, 0, r.right, r.bottom); //Π·Π°ΡΠΈΡΠΎΠ²ΡΠ²Π°Ρ ΡΠΈΠ½Π΅ΠΉ ΠΊΠΈΡΡΡΡ BITMAPINFO bi = { 0 }; bi.bmiHeader.biSize = sizeof(bi.bmiHeader); int er = GetDIBits(hdcc, bm, 0, 0, NULL, &bi, DIB_RGB_COLORS); //Π GetDIBits Π² ΠΊΠ°ΡΠ΅ΡΡΠ²Π΅ HDC Π΄ΠΎΠ»ΠΆΠ΅Π½ ΠΆΠ΅ ΡΠΎΠ²ΠΌΠ΅ΡΡΠ½ΡΠΉ Π²ΡΡΡΡΠΏΠ°ΡΡ, Π΄Π°? if (!er) { cout << "ERROR HERE:"<< GetLastError()<<"ENDS"; } COLORREF *buf = new COLORREF(bi.bmiHeader.biSizeImage); \\Π’Π°ΠΊ ΠΈ Π½Π΅ ΠΏΠΎΠ½ΡΠ» ΠΊΠ°ΠΊΠΎΠ³ΠΎ ΡΠΈΠΏΠ° Π΄ΠΎΠ»ΠΆΠ΅Π½ Π±ΡΡΡ ΠΌΠ°ΡΡΠΈΠ² - char, BYTE, COLORREF ΠΈΠ»ΠΈ ΠΊΠ°ΠΊΠΎΠΉ-ΡΠΎ Π΅ΡΡ bi.bmiHeader.biBitCount = 32; bi.bmiHeader.biCompression = BI_RGB; bi.bmiHeader.biHeight = abs(bi.bmiHeader.biHeight); GetDIBits(hdcc, bm, 0, bi.bmiHeader.biHeight, buf, &bi, DIB_RGB_COLORS); for (int i(0); i < 100; i++) { cout << (int)GetRValue(buf[i]) << ","; cout << (int)GetGValue(buf[i]) << ","; cout << (int)GetBValue(buf[i]) << ","; cout << endl; } SetDIBits(hdcc, bm, 0, bi.bmiHeader.biHeight, buf, &bi, DIB_RGB_COLORS); delete []buf; BitBlt(hdc, 0, 0, r.right, r.bottom, hdcc, 0, 0, SRCCOPY); DeleteObject(hb); DeleteDC(hdcc); DeleteObject(bm); EndPaint(hwnd, &ps); } break;