Ok, im trying with GetDIBits but i cant make it work.
It always returns senseless values.
I think im missing the purpose of HDC here. Can someone explain this please? I mean, what's it for???
Note:
1) The image is a screenshot which i take just before running the code by pressing 'PrtScreen' button on the keyboard.
2) GetDIBits scans line 500 which, since im on a resolution of 1280x1024, is approximately in the middle of the screen.
3) Color depth is 32bits.Code:#include <iostream> #include <windows.h> using namespace std; int main() { HBITMAP hBitmap; if (OpenClipboard(NULL)) { hBitmap = (HBITMAP)GetClipboardData(CF_DIB); if (hBitmap == NULL) { cout << "Failed to get the clipboard data."; return 0; } } else { cout << "Failed to open the clipboard!"; return 0; } HDC hdc=CreateCompatibleDC(NULL); BITMAPINFO bmi; bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); bmi.bmiHeader.biWidth = 1280; bmi.bmiHeader.biHeight = 1; bmi.bmiHeader.biPlanes = 1; bmi.bmiHeader.biBitCount = 32; bmi.bmiHeader.biCompression = BI_RGB; bmi.bmiHeader.biSizeImage = 0; bmi.bmiHeader.biXPelsPerMeter = 0; bmi.bmiHeader.biYPelsPerMeter = 0; bmi.bmiHeader.biClrUsed = 0; bmi.bmiHeader.biClrImportant = 0; BYTE scanned[4*1280]; int returnValue = GetDIBits(hdc,hBitmap,500,1,scanned,&bmi,DIB_RGB_COLORS); int r = scanned[2401]; int g = scanned[2402]; int b = scanned[2403]; cout << "returnValue = " << returnValue << "\n"; cout << "r = " << r << "\n"; cout << "g = " << g << "\n"; cout << "b = " << b << "\n"; CloseClipboard(); return 0; }


Reply With Quote
Bookmarks