从文件导出一个位图资源写成BMP位图文件

try { HINSTANCE ghInstApp = AfxGetInstanceHandle(); HRSRC hRsrc = FindResource(NULL, MAKEINTRESOURCE(IDB_BITMAP1), RT_BITMAP ); ASSERT(hRsrc); DWORD dwErr = GetLastError(); DWORD dwLen = SizeofResource(ghInstApp,hRsrc); ASSERT(dwLen); HGLOBAL hGlobal = LoadResource(ghInstApp,hRsrc); CFile file(_T("C://temp//a.bmp"), CFile::modeCreate | CFile::modeWrite); //构建一个文件头 BITMAPFILEHEADER bfh = {0};//位图文件头 bfh.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);//到位图数据的偏移量 bfh.bfSize = bfh.bfOffBits + dwLen - sizeof(BITMAPINFOHEADER) ;//文件总的大小 bfh.bfType = (WORD)0x4d42; file.Write(&bfh, sizeof(bfh)); file.Write(hGlobal, dwLen); file.Close(); } catch(...) { ASSERT(0); }

你可能感兴趣的:(c,File,null)