1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
void GetPixelsFromHDC(HDC Destination, int *pixels)
{
//Get HBITMAP, BITMAP and BITMAPINFO data:
HBITMAP hBitmap= (HBITMAP)GetCurrentObject (Destination,OBJ_BITMAP);
BITMAP structBitmapHeader;
memset( &structBitmapHeader, 0, sizeof(BITMAP) );
GetObject(hBitmap, sizeof(BITMAP), &structBitmapHeader);
//cout << "Width: " << structBitmapHeader.bmWidth << "\tHeight: " << structBitmapHeader.bmHeight << "\n";
BITMAPINFO bmi;
memset(&bmi, 0, sizeof(bmi));
bmi.bmiHeader.biSize = sizeof(bmi);
bmi.bmiHeader.biWidth = structBitmapHeader.bmWidth;
bmi.bmiHeader.biHeight = structBitmapHeader.bmHeight;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;
//Creating the pixels pointer:
pixels = (unsigned int*)malloc(bmi.bmiHeader.biWidth*bmi.bmiHeader.biHeight*sizeof(unsigned int));
HBITMAP hb =CreateDIBSection(Destination, &bmi, DIB_RGB_COLORS, &pixels, 0, 0);
if(hb==NULL) MessageBox(NULL, "error", "error", MB_OK);
HGDIOBJ r= SelectObject(Destination,hb);
if(r==NULL) MessageBox(NULL, to_string(GetLastError()).c_str(), "error no bitmap selected", MB_OK);
//Change the pixels values just for test:
for(int i=0; i<100; i++) pixels[i]=RGB(0,255,0);
}
|