码迷,mamicode.com
首页 > 其他好文 > 详细

GetBitmapFromScreen

时间:2014-09-28 21:31:55      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:style   color   io   ar   for   sp   on   c   amp   



int GetBitmapFromScreen() 

char *lpBuf; 
HBITMAP hBitmap,hOld ; 
HDC hDC,hcDC; 
BITMAP bb;BITMAPINFO b; 
HANDLE hp,fh=NULL; 
DWORD dwX,dwY; 
//*************** 
//dwX=GetSystemMetrics(SM_CXSCREEN); 
//dwY=GetSystemMetrics(SM_CYSCREEN); 
dwX=100; 
dwY=100; 
hDC=GetDC(0); 
hcDC=CreateCompatibleDC(hDC); 
hBitmap=CreateCompatibleBitmap(hDC,dwX,dwY); 
hOld=(HBITMAP)SelectObject(hcDC,hBitmap); 
BitBlt(hcDC,0, 0,dwX,dwY, hDC, 0, 0, SRCCOPY); 
bb.bmWidth=dwX; 
bb.bmHeight =dwY; 
bb.bmPlanes = 1; 
bb.bmWidthBytes=bb.bmWidth*3; 
bb.bmBitsPixel=3; 
bb.bmType=0; 
b.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 
b.bmiHeader.biWidth=dwX; 
b.bmiHeader.biHeight =dwY; 
b.bmiHeader.biPlanes = 1; 
b.bmiHeader.biBitCount =24; 
b.bmiHeader.biCompression = BI_RGB; 
b.bmiHeader.biSizeImage = 0; 
b.bmiHeader.biXPelsPerMeter = 0; 
b.bmiHeader.biYPelsPerMeter = 0; 
b.bmiHeader.biClrUsed = 0; 
b.bmiHeader.biClrImportant = 0; 
b.bmiColors[0].rgbBlue=8; 
b.bmiColors[0].rgbGreen=8; 
b.bmiColors[0].rgbRed=8; 
b.bmiColors[0].rgbReserved=0; 
hp=GetProcessHeap(); 
lpBuf=(char *)HeapAlloc(hp,HEAP_ZERO_MEMORY,bb.bmHeight*bb.bmWidth*4); 




GetDIBits(hcDC,hBitmap,0,dwY,lpBuf,&b,DIB_RGB_COLORS); 


///////////////////////////////////显示到桌面////////////////////////////////
CClientDC dc(NULL);
for (int i=0;i<100;i++)
{
for (int k=0;k<100;k++)
{
BYTE b = *lpBuf++;
BYTE g = *lpBuf++;
BYTE r = *lpBuf++;
dc.SetPixel(k+200,i+200,RGB(r,g,b));
//*lpBuf++;
}
}
/////////////////////////////////////////////////////////////////////////


ReleaseDC(NULL,hDC); 
DeleteDC(hcDC); 
DeleteObject(hBitmap); 
DeleteObject(hOld); 
HeapFree(hp,0,lpBuf); 
return true; 

GetBitmapFromScreen

标签:style   color   io   ar   for   sp   on   c   amp   

原文地址:http://blog.csdn.net/mao0514/article/details/39644517

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!