|
-
December 1st, 2009, 10:49 PM
#8
Re: Getting pixel Data from a Bitmap Handle
The article I was reading is at (http://www.codeguru.com/forum/showthread.php?t=412541)
Here's the working code:
Code:
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
HDC hDesktopDC = ::GetDC(::GetDesktopWindow());
HDC hMemDC = ::CreateCompatibleDC(hDesktopDC);
int iHRes = ::GetDeviceCaps(hDesktopDC,DESKTOPHORZRES),
iVRes = ::GetDeviceCaps(hDesktopDC,DESKTOPVERTRES),
iBPP = ::GetDeviceCaps(hDesktopDC,BITSPIXEL),
iClrPlane = ::GetDeviceCaps(hDesktopDC,PLANES);
unsigned int iAlloc = iHRes*iVRes*(iBPP >> 3)*iClrPlane;
BYTE *bySrcData,
*byDestData = new unsigned char[iAlloc];
HBITMAP hBMP;
HDC hDC;
HGLRC hRC;
MSG msg;
BITMAPINFO bi;
RECT r;
::memset(&bi.bmiHeader,0,sizeof(bi.bmiHeader));
bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
bi.bmiHeader.biWidth = iHRes;
bi.bmiHeader.biHeight = iVRes;
bi.bmiHeader.biPlanes = iClrPlane;
bi.bmiHeader.biBitCount = iBPP;
::Initialize(hInstance,hWnd,nCmdShow);
::InitOGL(hWnd,hDC,hRC,r);
::glPixelZoom((float)r.right/(float)iHRes,(float)r.bottom/(float)iVRes);
hBMP = ::CreateDIBSection(hMemDC,&bi,DIB_RGB_COLORS,(void **)&bySrcData,NULL,0);
::SelectObject(hMemDC,hBMP);
do {
if(::PeekMessage(&msg,NULL,0,0,PM_REMOVE)) {
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
::BitBlt(hMemDC,0,0,iHRes,iVRes ,hDesktopDC,0,0,SRCCOPY);
::memcpy(byDestData,bySrcData,iAlloc);
// ::Laplace(bySrcData,byDestData,iHRes,iVRes);
::glDrawPixels(iHRes,iVRes, GL_RGBA/*GL_LUMINANCE*/, GL_UNSIGNED_BYTE, byDestData);
::glFlush();
::SwapBuffers(hDC);
} while( msg.message != WM_QUIT);
::wglMakeCurrent(NULL,NULL);
::ReleaseDC(hWnd,hDC);
::wglDeleteContext(hRC);
::SelectObject(hMemDC,NULL);
::ReleaseDC(NULL,hMemDC);
::DeleteObject(hBMP);
delete[] byDestData;
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|