在文档类中重载OnOpenDocument((LPCTSTR lpszPathName)函数,根据bmp图象的格式依次读入文件头,位图信息头,调色板信息(通过创建逻辑调色板,将位图调色板的信息复制到逻辑调色板,然后再实现逻辑调色板),位图数据;

解决方案 »

  1.   

    这个我刚做完,很简单的,建议搂住看本图像处理的书,就都明白了,要是需要代码的话,我这里有,我邮箱[email protected].另外我是新手.
      

  2.   

    BOOL CDIB::LoadFromFile(CFile *pf)
    {
    BYTE *lpBitmap,*lpBits;
    BITMAPINFOHEADER *pInfo;
    int nWidth,nHeight,nBitCount,nLen,nByteWidth;
    nLen=pf->GetLength();
    RGBQUAD *pPalette;
    unsigned int PaletteSize; lpBitmap=new BYTE[nLen];
    pf->Read(lpBitmap,nLen);
    if (lpBitmap[0]!='B'&&lpBitmap[1]!='M')
    {
    //AfxMessageBox("非位图文件");
    delete[] lpBitmap;
    return FALSE;
    }
    pInfo=(BITMAPINFOHEADER *)(lpBitmap+sizeof(BITMAPFILEHEADER));
    nWidth=pInfo->biWidth;
    nHeight=pInfo->biHeight;
    nBitCount=pInfo->biBitCount;
    nByteWidth=BYTE_PER_LINE(nWidth,nBitCount);
    switch (nBitCount)
    {
    case 24:
    if (m_lpBits) delete[] m_lpBits;
    if (m_lpPalette) delete[] m_lpPalette;
    m_lpPalette=NULL;// nByteWidth=nWidth*3;
    // if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
    m_lpBits=new BYTE[nByteWidth*nHeight];
    lpBits=(BYTE *)pInfo+sizeof(BITMAPINFOHEADER);
    memcpy(m_lpBits,lpBits,nByteWidth*nHeight);
    break;
    case 8:
    case 4:
    // nByteWidth=int ((nBitCount/8.0)*nWidth);
    // if (nByteWidth%4) nByteWidth+=4-(nByteWidth%4);
    PaletteSize=1<<pInfo->biBitCount;
    if (pInfo->biClrUsed!=0 && pInfo->biClrUsed<PaletteSize) PaletteSize=pInfo->biClrUsed;
    lpBits=lpBitmap+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
    pPalette=(RGBQUAD *)lpBits;
    lpBits+=sizeof(RGBQUAD)*PaletteSize; if (m_lpBits) delete[] m_lpBits;
    m_lpBits=new BYTE[nByteWidth*nHeight];
    memcpy(m_lpBits,lpBits,nByteWidth*nHeight); if (m_lpPalette) delete[] m_lpPalette;
    m_lpPalette=new BYTE[sizeof(RGBQUAD)*PaletteSize];
    memcpy(m_lpPalette,pPalette,sizeof(RGBQUAD)*PaletteSize);
    break;
    default: //AfxMessageBox("无效位图");
    delete[] lpBitmap;
    return FALSE;
    }
    delete[] lpBitmap;
    m_nBitCount=nBitCount;
    m_nWidth=nWidth;
    m_nHeight=nHeight;
    return TRUE;
    }
      

  3.   

    使用LoadImage函数,API的,详见msdn
      

  4.   

    OLELoadPicture,不光BMP,直接包括JPG,GIF都可以读进去了。如果LZ想自己实现读BMP的过程的话就去查查DIB的存储方式。
      

  5.   

    如果只是想显示图片,方法有很多但是如果你想对图像数据进行处理,就首先要弄清不同BMP的格式然后按照格式打开并读取图像数据