我现在有位图数据在CBitmap中
欲将其连同其它数据一同保存到一个文件中,
用的方法是序列化方法
打开后再创建CBitmap
请问如何实现。解决后将给200分
请回答两次

解决方案 »

  1.   

    1)
    将CBitmap的位图句柄和调色板句柄连同
    其它数据保存起来,使其可序列化
    2)读出位图句柄和调色板句柄
    创建CBitmap对象
    CreateBitmapIndirect
      

  2.   

    ar<< 位图句柄<<调色板句柄<< 数据
    ar>> 位图句柄>>调色板句柄>>数据
      

  3.   

    只知道,怎样写入一个BMP文件中:// WriteDIB - Writes a DIB to file
    // 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;
    }
      

  4.   

    只知道,怎样写入一个BMP文件中:// WriteDIB - Writes a DIB to file
    // 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;
    }