1 BITMAPFILEHEADER bfh;//文件头 2 bfh.bfType=0x4d42; 3 bfh.bfOffBits=sizeof(bfh)+sizeof(BITMAPINFOHEADER); 4 bfh.bfSize=bfh.bfOffBits+m_nWidth*m_nHeight*3; 5 bfh.bfReserved1=0; 6 bfh.bfReserved2=0; 7 8 CFile file; 9 CFileFind findFile;10 if (findFile.FindFile(strpath))11 {12 file.Remove(strpath);13 }14 15 if(!file.Open(strpath,CFile::modeCreate|CFile::modeRead|CFile::modeWrite))16 {17 AfxMessageBox("error!");18 return;19 }20 file.Write(&bfh,sizeof(bfh)); 21 file.Write(m_pBmpInfo,sizeof(BITMAPINFOHEADER)); 22 file.Write(m_pBmpData,m_nWidth*m_nHeight*3); 23 file.Close();
PS:位图信息头文件定义
1 BITMAPINFO* m_pBmpInfo = new BITMAPINFO[sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)]; 2 m_pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER); 3 m_pBmpInfo->bmiHeader.biBitCount = 24; 4 m_pBmpInfo->bmiHeader.biWidth = m_nWidth; 5 m_pBmpInfo->bmiHeader.biHeight = 0-m_nHeight; 6 m_pBmpInfo->bmiHeader.biPlanes = 1; 7 m_pBmpInfo->bmiHeader.biCompression = BI_RGB; 8 m_pBmpInfo->bmiHeader.biSizeImage = 0; 9 m_pBmpInfo->bmiHeader.biXPelsPerMeter = 0;10 m_pBmpInfo->bmiHeader.biYPelsPerMeter = 0;11 m_pBmpInfo->bmiHeader.biClrUsed = 0;12 m_pBmpInfo->bmiHeader.biClrImportant = 0;