高手求救 怎样用Serialize(CArchive & ar)的方法保存和打开CBitmap中的位图信息 热心就给分!!!! 我现在有位图数据在CBitmap中欲将其连同其它数据一同保存到一个文件中,用的方法是序列化方法打开后再创建CBitmap请问如何实现。解决后将给200分请回答两次 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 1)将CBitmap的位图句柄和调色板句柄连同其它数据保存起来,使其可序列化2)读出位图句柄和调色板句柄创建CBitmap对象CreateBitmapIndirect ar<< 位图句柄<<调色板句柄<< 数据ar>> 位图句柄>>调色板句柄>>数据 只知道,怎样写入一个BMP文件中:// WriteDIB - Writes a DIB to file// Returns - TRUE on success// szFile - Name of file to write to// hDIB - Handle of the DIBBOOL WriteDIB( LPTSTR szFile, HANDLE hDIB){ BITMAPFILEHEADER hdr; LPBITMAPINFOHEADER lpbi; if (!hDIB) return FALSE; CFile file; if( !file.Open( szFile, CFile::modeWrite|CFile::modeCreate) ) return FALSE; lpbi = (LPBITMAPINFOHEADER)hDIB; int nColors = 1 << lpbi->biBitCount; // Fill in the fields of the file header hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM" hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr ); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize + nColors * sizeof(RGBQUAD)); // Write the file header file.Write( &hdr, sizeof(hdr) ); // Write the DIB header and the bits file.Write( lpbi, GlobalSize(hDIB) ); return TRUE;} 只知道,怎样写入一个BMP文件中:// WriteDIB - Writes a DIB to file// Returns - TRUE on success// szFile - Name of file to write to// hDIB - Handle of the DIBBOOL WriteDIB( LPTSTR szFile, HANDLE hDIB){ BITMAPFILEHEADER hdr; LPBITMAPINFOHEADER lpbi; if (!hDIB) return FALSE; CFile file; if( !file.Open( szFile, CFile::modeWrite|CFile::modeCreate) ) return FALSE; lpbi = (LPBITMAPINFOHEADER)hDIB; int nColors = 1 << lpbi->biBitCount; // Fill in the fields of the file header hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM" hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr ); hdr.bfReserved1 = 0; hdr.bfReserved2 = 0; hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize + nColors * sizeof(RGBQUAD)); // Write the file header file.Write( &hdr, sizeof(hdr) ); // Write the DIB header and the bits file.Write( lpbi, GlobalSize(hDIB) ); return TRUE;} 菜鸟求助 fseek和sacnf的问题! 急!!!显示一个变化的圆 怎样在DLL内部广播消息 没人回答吗,再开一贴。能解决,100分相送,决不食言!!! email收发程序编写请教 关于文件操作问题,菜鸟问题 在线求助。 ADO访问SQL数据库问题? Windows原来是这样开始的 怎样提取命令行提示符中获取的信息 请教:LRESULT CALLBAK WndProc( HWND, UINT, WPARAM, LPARAM )
将CBitmap的位图句柄和调色板句柄连同
其它数据保存起来,使其可序列化
2)读出位图句柄和调色板句柄
创建CBitmap对象
CreateBitmapIndirect
ar>> 位图句柄>>调色板句柄>>数据
// Returns - TRUE on success
// szFile - Name of file to write to
// hDIB - Handle of the DIB
BOOL WriteDIB( LPTSTR szFile, HANDLE hDIB)
{
BITMAPFILEHEADER hdr;
LPBITMAPINFOHEADER lpbi; if (!hDIB)
return FALSE; CFile file;
if( !file.Open( szFile, CFile::modeWrite|CFile::modeCreate) )
return FALSE; lpbi = (LPBITMAPINFOHEADER)hDIB; int nColors = 1 << lpbi->biBitCount; // Fill in the fields of the file header
hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM"
hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr );
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize +
nColors * sizeof(RGBQUAD)); // Write the file header
file.Write( &hdr, sizeof(hdr) ); // Write the DIB header and the bits
file.Write( lpbi, GlobalSize(hDIB) ); return TRUE;
}
// Returns - TRUE on success
// szFile - Name of file to write to
// hDIB - Handle of the DIB
BOOL WriteDIB( LPTSTR szFile, HANDLE hDIB)
{
BITMAPFILEHEADER hdr;
LPBITMAPINFOHEADER lpbi; if (!hDIB)
return FALSE; CFile file;
if( !file.Open( szFile, CFile::modeWrite|CFile::modeCreate) )
return FALSE; lpbi = (LPBITMAPINFOHEADER)hDIB; int nColors = 1 << lpbi->biBitCount; // Fill in the fields of the file header
hdr.bfType = ((WORD) ('M' << 8) | 'B'); // is always "BM"
hdr.bfSize = GlobalSize (hDIB) + sizeof( hdr );
hdr.bfReserved1 = 0;
hdr.bfReserved2 = 0;
hdr.bfOffBits = (DWORD) (sizeof( hdr ) + lpbi->biSize +
nColors * sizeof(RGBQUAD)); // Write the file header
file.Write( &hdr, sizeof(hdr) ); // Write the DIB header and the bits
file.Write( lpbi, GlobalSize(hDIB) ); return TRUE;
}