pImageData指向位图的数据,如何在客户区中显示出来?
//BYTE* pImageData;
HDC hScreenDC = CreateDC("DISPLAY",NULL,NULL,NULL);
int iWidth = GetDeviceCaps(hScreenDC,HORZRES);
int iHeight = GetDeviceCaps(hScreenDC,VERTRES);
HDC hMemDC = CreateCompatibleDC(hScreenDC);
HBITMAP hScreenDDB = CreateCompatibleBitmap(hScreenDC,iWidth,iHeight);
SelectObject(hMemDC,hScreenDDB);
BitBlt(hMemDC,0,0,iWidth,iHeight,hScreenDC,0,0,SRCCOPY);
BITMAP bitmapInfo;
GetObject(hScreenDDB,sizeof(BITMAP),&hScreenDDB);
BITMAPINFOHEADER bih;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biHeight = bitmapInfo.bmWidth;
bih.biPlanes = 1;
bih.biBitCount = (WORD)bitmapInfo.bmPlanes * bitmapInfo.bmBitsPixel;
bih.biCompression = BI_RGB;
bih.biSizeImage = 0;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;
BOOL bHasPalette = FALSE;
if(bih.biBitCount <=8){
bHasPalette = TRUE;
}
DWORD dwBmpInfoSize = sizeof(BITMAPINFOHEADER) + (bHasPalette ? 1 << bih.biBitCount : 0) * sizeof(RGBQUAD);
LPBITMAPINFO pBmpInfo = (LPBITMAPINFO)new char[dwBmpInfoSize];
memcpy((void*)&(pBmpInfo->bmiHeader), (void*)&bih, sizeof(BITMAPINFOHEADER));
if(bHasPalette){
//初始化调色板的代码,该如何写?
}
GetDIBits(hScreenDC, hScreenDDB, 0, iHeight, NULL, pBmpInfo, DIB_RGB_COLORS);
BYTE* pImageData = new BYTE[pBmpInfo->bmiHeader.biSizeImage];
GetDIBits(hScreenDC, hScreenDDB, 0, iHeight, pImageData, pBmpInfo, DIB_RGB_COLORS);
大家看我这个pImageData是不是已经指向了屏幕位图对应的实际数据了,这是服务端,然后要把这个发送到客户端,然后在客户端的客户区中显示出来,该怎么做啊,好象要用到什么调色板什么的,是不是啊
问题点数:20、回复次数:3Top
1 楼bxnaa()回复于 2006-05-04 21:47:22 得分 0
顶起Top
2 楼bxnaa()回复于 2006-05-05 09:04:00 得分 0
我加点注释,大家看的清楚点
HDC hScreenDC = CreateDC("DISPLAY",NULL,NULL,NULL);//得到整个屏幕的DC句柄
int iWidth = GetDeviceCaps(hScreenDC,HORZRES);
int iHeight = GetDeviceCaps(hScreenDC,VERTRES);
HDC hMemDC = CreateCompatibleDC(hScreenDC);
HBITMAP hScreenDDB = CreateCompatibleBitmap(hScreenDC,iWidth,iHeight);
SelectObject(hMemDC,hScreenDDB);
BitBlt(hMemDC,0,0,iWidth,iHeight,hScreenDC,0,0,SRCCOPY);
//得到DDB信息
BITMAP bitmapInfo;
GetObject(hScreenDDB,sizeof(BITMAP),&hScreenDDB);
//构造BITMAPINFOHEADER结构
BITMAPINFOHEADER bih;
bih.biSize = sizeof(BITMAPINFOHEADER);
bih.biHeight = bitmapInfo.bmWidth;
bih.biPlanes = 1;
bih.biBitCount = (WORD)bitmapInfo.bmPlanes * bitmapInfo.bmBitsPixel;
bih.biCompression = BI_RGB;
bih.biSizeImage = 0;
bih.biXPelsPerMeter = 0;
bih.biYPelsPerMeter = 0;
bih.biClrUsed = 0;
bih.biClrImportant = 0;
//判断是否有调色版
BOOL bHasPalette = FALSE;
if(bih.biBitCount <=8){
bHasPalette = TRUE;
}
//构造BITMAPINFO结构
DWORD dwBmpInfoSize = sizeof(BITMAPINFOHEADER) + (bHasPalette ? 1 << bih.biBitCount : 0) * sizeof(RGBQUAD);
LPBITMAPINFO pBmpInfo = (LPBITMAPINFO)new char[dwBmpInfoSize];
memcpy((void*)&(pBmpInfo->bmiHeader), (void*)&bih, sizeof(BITMAPINFOHEADER));
if(bHasPalette){
//初始化调色板的代码,该如何写?
}
//得到DIB数据长度
GetDIBits(hScreenDC, hScreenDDB, 0, iHeight, NULL, pBmpInfo, DIB_RGB_COLORS);
//获得DIB数据
BYTE* pImageData = new BYTE[pBmpInfo->bmiHeader.biSizeImage];
GetDIBits(hScreenDC, hScreenDDB, 0, iHeight, pImageData, pBmpInfo, DIB_RGB_COLORS);Top
3 楼bxnaa()回复于 2006-05-05 14:20:24 得分 0
实际上就是做个远程屏幕监控的,哪位高手做过相关的,教教小弟啊~,请加QQ:411456361或MSN:bxnaa@hotmail.com,谢谢了!现在我比较急,因为这是毕业设计的题目,马上就要交了,才做了一点点,后面还有图象压缩编码,传输,定时刷新,哎,急啊
Top




