我用mfc编了个画笔程序,请问怎么将已经画好的东西存成bmp文件压
难道要很详细的了解bmp的数据结构嘛??
有没有一个什么已经有的类,可以比较容易的搞定??
CDib类好象只能load保存的话,好象不太型
别人的mfc程序不好看懂雅
请问高人了!!!!!
高分相送
拜托了!!!!

解决方案 »

  1.   

    you can ues the serial implement .
    but serial implement isn't offer directly by mfc.
    so you can find the bmp ocx .
    last year i programmed a porject which is about bmp ,in that porject i save a bmp picture as a file ,but i'm sorry i don't remember the name of the that bmp ocx.
      

  2.   

    //计算调色板大小
    if (wBitCount <= 8)
    {
    dwPaletteSize = (1 << wBitCount) * sizeof(RGBQUAD);
    }
    //创建文件
    fh = CreateFile(lpFileName, GENERIC_WRITE, CREATE_ALWAYS,0, NULL, 
    FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, NULL);
    // 处理调色板 
    hPal = GetStockObject(DEFAULT_PALETTE);
    if (hPal)
    {
    hDC = GetDC(NULL);
    hOldPal = SelectPalette(hDC, (HPALETTE)hPal, FALSE);
    RealizePalette(hDC);
    } //设置位图信息头结构
    bi.biSize = sizeof(BITMAPINFOHEADER);
    bi.biWidth = Bitmap.bmWidth;
    bi.biHeight = Bitmap.bmHeight;
    bi.biPlanes = 1;
    bi.biBitCount = wBitCount;
    bi.biCompression = BI_RGB;
    bi.biSizeImage = 0;
    bi.biXPelsPerMeter = 0;
    bi.biYPelsPerMeter = 0;
    bi.biClrUsed = 0;
    bi.biClrImportant = 0;
    // 设置位图文件头
    bmfHdr.bfType = 0x4D42; // "BM"
    dwDIBSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + dwPaletteSize + dwBmBitsSize; 
    bmfHdr.bfSize = dwDIBSize;
    bmfHdr.bfReserved1 = 0;
    bmfHdr.bfReserved2 = 0;
    bmfHdr.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + (DWORD)sizeof(BITMAPINFOHEADER) + dwPaletteSize;
    // 写入位图文件头
    WriteFile(fh, (LPSTR)&bmfHdr, sizeof(BITMAPFILEHEADER), &dwWritten, NULL);
    // 写入位图文件其余内容
    WriteFile(fh, (LPSTR)lpbi, dwDIBSize, &dwWritten, NULL);