mfc里面的view类ondraw函数画了几个简单图形 请问怎么把view保存成一个bmp
展开全部
void SaveDCtoBmp(CDC *pMemDC, CArchive& ar)
{
BITMAPINFO bi;
BITMAPINFOHEADER *pbi= &bi.bmiHeader;
HBITMAP hbm = ::CreateCompatibleBitmap(pMemDC->m_hDC,
1, 1);
HBITMAP hold = (HBITMAP)::SelectObject(pMemDC->m_hDC,
hbm);
pbi->biSize = sizeof(BITMAPINFOHEADER);
pbi->biBitCount = 0;
int n =
GetDIBits(pMemDC->m_hDC,hold,0,1,NULL,&bi,DIB_RGB_COLORS);
pbi->biBitCount = 24;
pbi->biCompression = 0;
pbi->biSizeImage = pbi->biWidth * pbi->biHeight * 3;
BYTE *pBits = new BYTE[pbi->biSizeImage];
n = GetDIBits(pMemDC->m_hDC,hold,0,pbi->biHeight,
pBits, &bi, DIB_RGB_COLORS);
hbm = (HBITMAP)::SelectObject(pMemDC->m_hDC, hold);
DeleteObject(hbm);
BITMAPFILEHEADER hdr;
hdr.bfType=0x4D42;
hdr.bfSize=sizeof(BITMAPFILEHEADER)+pbi->biSize+pbi->biSizeImage;
hdr.bfReserved1 = hdr.bfReserved2 = 0;
hdr.bfOffBits=(DWORD)sizeof(BITMAPFILEHEADER)+pbi->biSize;
ar.Write(&hdr,sizeof(BITMAPFILEHEADER));
ar.Write(pbi,sizeof(BITMAPINFOHEADER));
ar.Write(pBits,pbi->biSizeImage);
delete [] pBits;
} // SaveDCtoBmp()
你可以自己构造一个archive对象,或者最后写文件的部分改成CFile,或者API CreateFile WriteFile什么的
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询