拷贝桌面屏幕指定的区域Rect(100,100,400,400)到缓冲区中Buffer[300][300],其中Buffer是:struct tag_RGB
{
BYTE r;
BYTE g;
BYTE b;
}tag_RGB buffer[300][300];
请指点. QQ:123866716
{
BYTE r;
BYTE g;
BYTE b;
}tag_RGB buffer[300][300];
请指点. QQ:123866716
调试欢乐多
{
CBitmap bitmap;
CWindowDC dc(pWnd);
CDC memDC;
CRect rect; memDC.CreateCompatibleDC(&dc); pWnd->GetWindowRect(rect);
//用窗口区域大小定义一个内存DC ,并将窗口图像暂存其中
bitmap.CreateCompatibleBitmap(&dc, rect.Width(),rect.Height() ); CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
memDC.BitBlt(0, 0, rect.Width(),rect.Height(), &dc, 0, 0, SRCCOPY); // 如果设备支持调色板,创建调色板
CPalette pal;
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE )
{
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300; pLP->palNumEntries =
GetSystemPaletteEntries( dc, 0, 255, pLP->palPalEntry ); // Create the palette
pal.CreatePalette( pLP ); delete[] pLP;
} memDC.SelectObject(pOldBitmap); // 转换 bitmap 到 a DIB
HANDLE hDIB = DDBToDIB( bitmap, BI_RGB, &pal ); if( hDIB == NULL )
return FALSE; // Write it to file
WriteDIB( szFile, hDIB ); // Free the memory allocated by DDBToDIB for the DIB
GlobalFree( hDIB );
return TRUE;
}
??这个函数是写hDIB到File吧 (那儿定义,这个到没必要!我不要保存成文件)这个函数没有实现我的问题!!!!
不过还是得谢谢!
HDC hdc, // handle to DC
int nXPos, // x-coordinate of pixel
int nYPos // y-coordinate of pixel
);
也可以
你参考参考吧
CWindowDC dc(NULL);//NULL代表是桌面,this代表当前窗口
CBitmap bm;CRect rect(100,100,400,400);
int Width=rect.Width();
int Height=rect.Height();bm.CreateCompatibleBitmap(&dc,Width,Height);
CDC tdc;
tdc.CreateCompatibleDC(&dc);
CBitmap*pOld=tdc.SelectObject(&bm);
tdc.BitBlt(0,0,Width,Height,&dc,0,0,SRCCOPY);
tdc.SelectObject(pOld);
BITMAP btm;
bm.GetBitmap(&btm);
DWORD size=btm.bmWidthBytes*btm.bmHeight;
LPSTR lpData=(LPSTR)GlobalAlloc(GPTR,size);BITMAPINFOHEADER bih;
bih.biBitCount=btm.bmBitsPixel;
bih.biClrImportant=0;
bih.biClrUsed=0;
bih.biCompression=0;
bih.biHeight=btm.bmHeight;
bih.biPlanes=1;
bih.biSize=sizeof(BITMAPINFOHEADER);
bih.biSizeImage=size;
bih.biWidth=btm.bmWidth;
bih.biXPelsPerMeter=0;
bih.biYPelsPerMeter=0;
GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS);GlobalFree(lpData);
先全屏拷贝,然后根据分辨率,自己依次去取Rect(100,100,400,400)
{
BYTE r;
BYTE g;
BYTE b;
}
你这样定义tag_RGB,那就更是只能自己取了。
因为屏幕拷贝,都是一个象素4个字节,还有一个Alpha(透明度),只是有时候才需要用这个值。理论上说,自己取也并不是很麻烦。如果今晚有空,大家可以一起探讨写写看。
然后用ScanLine()依次扫描各行
得到Byte *;
TColor Color
GetRValue();
GetGValue();
GetBValue();
谁有更快的速度的代码贴出来,我再加分!
GetDIBits(dc,bm,0,bih.biHeight,lpData,(BITMAPINFO*)&bih,DIB_RGB_COLORS); struct tag_RGB
{
BYTE b;
BYTE g;
BYTE r;
BYTE alpha;
};
tag_RGB **buffer1=(tag_RGB **)lpData;
int x = buffer1[0][0].r;
int a = buffer1[299][299].alpha; GlobalFree(lpData);