按照位图的格式,写到文件就可以了。
MSDN中的DIBLOOK例子,从BMP的打开到保存都有,可以自己看看。
在这里可能会得到一些零散的回答,即使这个问题解决了,可能还会有其它的问题。

解决方案 »

  1.   

    这位laoma_hbu,你好,你能给我一些代码吗?我看了MSDN的例子可还是不会,我vc的才学一周多,现在经理叫我做vc图像处理,我真的不知道怎么办了,求求你了,我的适用期还没过,挺担心的。谢谢你的回答。
      

  2.   

    以下是保存RGB24的彩色bmp文件的例子,黑白位图你可以自己改一下,pBuf中已经是位图数据了
    // open file
    HANDLE hSnapshotFile = CreateFile(szFilename, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if ( NULL == hSnapshotFile )
    {
    delete []pBuf;
    return HRESULT_FROM_WIN32(GetLastError());
    } // write BMP file header
    DWORD nWritten = 0;
    UINT32 nImageSize = nWidth * nHeight * 3;
    BITMAPFILEHEADER bmpHeader;
    BITMAPINFOHEADER bmiHeader;
    bmpHeader.bfType = 'MB';
    bmpHeader.bfSize = nImageSize + sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);;
    bmpHeader.bfReserved1 = 0;
    bmpHeader.bfReserved2 = 0;
    bmpHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
    bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
    bmiHeader.biWidth = nWidth;
    bmiHeader.biHeight = nHeight;
    bmiHeader.biPlanes = 1;
    bmiHeader.biBitCount = 24;
    bmiHeader.biCompression = BI_RGB;
    bmiHeader.biSizeImage = nImageSize;
    bmiHeader.biXPelsPerMeter = 0;
    bmiHeader.biYPelsPerMeter = 0;
    bmiHeader.biClrUsed = 0;
    bmiHeader.biClrImportant = 0;
    if ( !WriteFile(hSnapshotFile, &bmpHeader, sizeof(bmpHeader), &nWritten, NULL) )
    {
    delete []pBuf;
    CloseHandle(hSnapshotFile);
    return HRESULT_FROM_WIN32(GetLastError());
    }
    if ( !WriteFile(hSnapshotFile, &bmiHeader, sizeof(bmiHeader), &nWritten, NULL) )
    {
    delete []pBuf;
    CloseHandle(hSnapshotFile);
    return HRESULT_FROM_WIN32(GetLastError());
    } // BMP file data
    for ( INT32 y = nHeight - 1; y >= 0; y-- )
    {
    if ( !WriteFile(hSnapshotFile, pBuf + y * nWidth * 3, nWidth * 3, &nWritten, NULL) )
    {
    delete []pBuf;
    CloseHandle(hSnapshotFile);
    return HRESULT_FROM_WIN32(GetLastError());
    }
    } // free memory
    delete []pBuf; // close file
    CloseHandle(hSnapshotFile);
      

  3.   

    hugeice你写错了,我要保存的是8位灰度化的位图,还有没有人会写啊,谢谢
      

  4.   

    这个东西你看下BMP的结构就知道,就是那么一些东西
    如果你有VC基础,一个星期绝对可以搞定。