最近做课程设计,关于单文档下的位图显示,如何读入指定目录下的BMP图像并显示在窗口中,希望大家能给个方法,不胜感激

解决方案 »

  1.   

    www.vckbase.com上有现成的例子、
    也可以用一个picture控件也可以哦
      

  2.   

    读入BMP文件:
    HBITMAP  hBmp = LoadImage(NULL, strBmpFilePath,   IMAGE_BITMAP, 0,0,LR_LOADFROMFILE);
    m_bmp.Attach(hBmp);画:
    OnDraw(CDC* pDC)
    {
      CDC  memDC;
      memDC.CreateCompatibleDC(pDC);
      
      BITMAP  bitmap;
      m_bmp.GetBitmap(&bitmap);
      CBitmap* pob = pDC->SelectObject(&m_bmp);
      pDC->BitBlt(0,0, bitmap.bmWidth, bitmap.bmHeight, &memDC, 0,0);}
      

  3.   

    在OnDraw函数中:
             CString strFileName = "d:\\a.bmp"; // 文件名
    HBITMAP hBmp = (HBITMAP)LoadImage(NULL,strFileName,IMAGE_BITMAP,0,0,LR_DEFAULTSIZE|LR_LOADFROMFILE); if (hBmp != NULL)
    {
    CBitmap bmp;
    bmp.Attach(hBmp); BITMAP bmpInfo;
    bmp.GetBitmap(&bmpInfo);

    CDC dcMemory;
    dcMemory.CreateCompatibleDC(pDC);

    CBitmap* pOldBitmap = dcMemory.SelectObject(&bmp);

    CRect rect;
    GetClientRect(&rect);
    int nX = rect.left + (rect.Width() - bmpInfo.bmWidth) / 2;
    int nY = rect.top + (rect.Height() - bmpInfo.bmHeight) / 2;

    pDC->BitBlt(nX, nY, bmpInfo.bmWidth, bmpInfo.bmHeight, &dcMemory, 
    0, 0, SRCCOPY);

    dcMemory.SelectObject(pOldBitmap);
    }