首页 > 代码库 > GetBitmapFromScreen
GetBitmapFromScreen
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。