请问如何将位图读入???既从菜单“打开”中选取文件,然后确定,就在视图中显示位图……相信很多人都知道的……如果能给出实现的函数更好了先谢谢了:)

解决方案 »

  1.   

    http://www.vckbase.com/document/viewdoc.asp?id=446
      

  2.   

    原来还真有这个程序。
    后来不知道放哪去了。
    你看看<<Visual C++ 6.0时尚编程百例>>中的[实例 23 位图显示],
    那上面有。
      

  3.   

    BMP的……
    我知道如何加载,但我想开始让客户区先为空,然后从菜单“打开”中选取文件,
    按“打开”后,显示位图。
      

  4.   

    先用CFileDialog选择文件,然后写位图显示代码。找个例子看看就知道了:)
    我这里有一个是在dialog base程序中的ImgEdit控件显示bmp的,(注释掉的你不要管)。SDI的你看看书就找到了,就是LoadImage、或creatImage然后Bitblt.....
    void COcr3Dlg::OnFileLoadImage() 
    {
    int result,len,i;
    LPTSTR lpPath,lpExt;
    CFileDialog *pFileDlg = new CFileDialog(TRUE);
    pFileDlg->m_ofn.lpstrFilter = "BMP FILES\0*.bmp\0TIF FILES\0*.tif\0JPG FILES\0*.JPG\0FAX FILES\0*.fax\0PCX FILES\0*.pcx\0\0";
    pFileDlg->m_ofn.lpstrDefExt = "*.bmp";
    result = pFileDlg->DoModal();
    if( result == IDOK )
    {
    m_strImgFileName = pFileDlg->GetPathName();
    }
    delete pFileDlg;
    lpPath = m_strImgFileName.GetBuffer(_MAX_PATH);
    m_strImgFileName.ReleaseBuffer();
    len = m_strImgFileName.GetLength();
    for( i = len-1;i >= 0;i--)
    {
    if( lpPath[i] == '.' )
    break;
    }
    lpExt = &lpPath[i+1];
    if( strstr(_strupr((char*)lpExt),"BMP") )
    {
    m_bRecogBmp=true;
    m_hBitmap=(HBITMAP)::LoadImage(NULL,m_strImgFileName.GetBuffer(_MAX_PATH),
    IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
    m_strImgFileName.ReleaseBuffer();
    }
    /*else if( strstr(_strupr((char*)lpExt),"TIF") )
    {
    m_bRecogTif = true;
    HLSection *pHLSection = new HLSection();
    if( pHLSection->DecodeImage(lpPath) )
    {
    int nWidth,nHeight,nW,nBytePL;
    CBitmap *pBitmap = new CBitmap();
    BYTE *pBuf = pHLSection->GetImageBuf();
    nWidth = pHLSection->GetImageWidth();
    nHeight = pHLSection->GetImageHeight();
    pBitmap->CreateBitmap(nWidth,nHeight,1,1,NULL);
    nW = nWidth;
    if(nW%8)
    nW += 8-nW%8;
    nBytePL = nW>>3;
    //令每行字节数为偶数,否则在显示时将会出现乱屏现象
    if( nBytePL%2 )
    {
    BYTE *pData = new BYTE[(nBytePL+1)*nHeight];
    for( int i = 0;i < nHeight;i ++ )
    {
    for( int j = 0;j < nBytePL;j ++ )
    {
    pData[i*(nBytePL+1)+j] = pBuf[i*nBytePL+j];
    }
    pData[i*(nBytePL+1)+nBytePL] = 0;
    }
    nWidth += 8;
    nBytePL += 1;
    pBuf = pData;
    }
    pBitmap->SetBitmapBits(nBytePL*nHeight,pBuf);
    m_hBitmap = (HBITMAP)pBitmap->GetSafeHandle();
    }
    else
    {
    return;
    }
    delete pHLSection;
    }*/
    /*else
    {
    //other image formats
    }*/
    m_ImgEdit.SetImage(m_strImgFileName.GetBuffer(_MAX_PATH));
    m_strImgFileName.ReleaseBuffer();
    m_ImgEdit.Display();
    }