GetPixel and getting a screenshot.

This is a discussion on GetPixel and getting a screenshot. within the Windows Programming forums, part of the Platform Specific Boards category; Yes... GetDIBits() Which language are you using that can access some of the WIN32 API (in a DLL) but not ...

  1. #16
    train spotter
    Join Date
    Aug 2001
    near a computer


    Which language are you using that can access some of the WIN32 API (in a DLL) but not all of it?
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  2. #17
    Registered User
    Join Date
    Mar 2005
    Mountaintop, Pa
    You do realize that you do not need either GetPixel or SetPixel calls. Both can be accomplished by the use of bit shifting to get or set the appropriate RGB values.

  3. #18
    Registered User
    Join Date
    Mar 2009

    Arrow how to get pixels

    	HDC hdcc = CreateCompatibleDC(hdc);
    //hdc - is your dc which you copy from
    	HBITMAP hBm = CreateCompatibleBitmap(hdc, iSrcW, iSrcH);
    //iSrcW, iSrcH - size of you sourse hdc
    	HBITMAP hOldBm = (HBITMAP)SelectObject(hdcc, hBm);
    	BitBlt(hdcc, 0, 0, iSrcW, iSrcH, hdc, iX, iY, SRCCOPY);
    // now, get info from copied bitmap
    	BITMAP bm;
    	memset(&bm, 0, sizeof BITMAP);
    	int iErr = GetObject(hBm, sizeof(BITMAP), &bm);
    	iErr = GetLastError();
    	iBPP = bm.bmBitsPixel;
    	DIBSECTION dis;
    	iErr = GetObject(hBm, sizeof(DIBSECTION), &dis);
    	int length = (bm.bmWidth * bm.bmHeight) * (bm.bmBitsPixel>>3);
    	if(0 == length)
    		return NULL;// nothing to do
    // Ok, bitmap info now
    	memset(&bi, 0, sizeof BITMAPINFO);
    	BYTE *pBits = new BYTE[length];
    	bi.bmiHeader.biSize          = sizeof(BITMAPINFOHEADER);
    	bi.bmiHeader.biWidth         = bm.bmWidth;
    	bi.bmiHeader.biHeight        = bm.bmHeight;
    	bi.bmiHeader.biPlanes        = 1;
    	bi.bmiHeader.biBitCount      = bm.bmPlanes * bm.bmBitsPixel;
    	bi.bmiHeader.biCompression   = 0;
    	bi.bmiHeader.biSizeImage     = 0;
    	bi.bmiHeader.biXPelsPerMeter = 0;
    	bi.bmiHeader.biYPelsPerMeter = 0;
    	bi.bmiHeader.biClrUsed       = 0;
    	bi.bmiHeader.biClrImportant  = 0;
    	LPBYTE lpBits = (LPBYTE) GlobalAlloc(GMEM_FIXED, length);
    	int iBits = GetDIBits(hdc, hBm, 0, bm.bmHeight, lpBits, &bi, DIB_RGB_COLORS);
    //.......  now you got bits of your pixels in lpBits
    // remember, that y-axis begun from bottom of screen
    // and don't forget:
    	SelectObject(hdcc, hOldBm);
    Good luck!

  4. #19
    Registered User
    Join Date
    Apr 2007
    Quote Originally Posted by DeskEx View Post
    Good luck!
    See MSDN code.

  5. #20
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    New Zealand
    Seriously, forget that SetPixel and GetPixel exist. They are completely useless. Using them is like walking down the road to the store to buy a single paperclip every time you need one, even though you go through about 200+ per day.
    Bitblt on the other hand would be like buying a bag full of them.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21