读书人

已有像素点矩阵在内存中CDC怎么得到

发布时间: 2012-08-24 10:00:20 作者: rapoo

已有像素点矩阵在内存中,CDC如何得到
rt,CDC如何能得到并处理内存中已存在的像素点矩阵

[解决办法]
// get mem
unsigned fsize;
fsize =if_hnd.GetLength();//
BYTE *ScreenPtr1=0;
ScreenPtr1=(BYTE *)new char[fsize]; //
// read all in
if_hnd.Read(ScreenPtr1,fsize);// 数据在这里
// image data are in buffer
if(if_hnd) if_hnd.Close();
// make bitmap info
LPBITMAPINFO pBMPinfo;
pBMPinfo=(LPBITMAPINFO)new BYTE[sizeof(BITMAPINFOHEADER)+16*sizeof(RGBQUAD)];
ZeroMemory(&pBMPinfo->bmiHeader,sizeof(BITMAPINFOHEADER));
pBMPinfo->bmiHeader.biSize=sizeof(BITMAPINFOHEADER);
pBMPinfo->bmiHeader.biBitCount=4;
pBMPinfo->bmiHeader.biWidth=648;
pBMPinfo->bmiHeader.biHeight=508;
pBMPinfo->bmiHeader.biPlanes=1;
pBMPinfo->bmiHeader.biSizeImage=648*508/2;
// copy colors
for(int jj=0; jj<16; jj++)
{// reversed !
pBMPinfo->bmiColors[jj].rgbReserved=0;
pBMPinfo->bmiColors[jj].rgbRed=(BYTE)(color_table[jj] & 0x0000FF);
pBMPinfo->bmiColors[jj].rgbGreen=(BYTE)((color_table[jj] & 0x00FF00) >> 8);
pBMPinfo->bmiColors[jj].rgbBlue=(BYTE)((color_table[jj] & 0xFF0000) >> 16);
}
// draw bmp
pDC->SetStretchBltMode(COLORONCOLOR);
StretchDIBits(pDC->GetSafeHdc(),0,0,wid,hei,0,0,wid,hei,
ScreenPtr1,
pBMPinfo,
DIB_RGB_COLORS,SRCCOPY);
// free
delete pBMPinfo;
delete [] ScreenPtr1;
return;

[解决办法]
SetDIBitsToDevice

读书人网 >VC/MFC

热点推荐