mfc里bitmap 几种加载方式

  1. 1 //在对话框内显示位图
      CBitmap hbmp;
      HBITMAP hbitmap;
      //装载图片文件MM.bmp
      hbitmap=(HBITMAP)::LoadImage(::AfxGetInstanceHandle(),"MM.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
      hbmp.Attach(hbitmap);
      //获取图片格式
      BITMAP bm;
      hbmp.GetBitmap(&bm);
      CDC dcMem;
      dcMem.CreateCompatibleDC(GetDC());
      CBitmap * poldBitmap=(CBitmap*)dcMem.SelectObject(hbmp);
      CRect lRect;
      GetClientRect(&lRect);
      lRect.NormalizeRect();
      //显示位图
    mfc里bitmap 几种加载方式_第1张图片
  2.   GetDC()-2 2 2>StretchBlt(lRect.left,lRect.top,lRect.Width(),lRect.Height(),&dcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
      dcMem.SelectObject(&poldBitmap);
      //在Static控件内显示位图
      CBitmap hbmp;
      HBITMAP hbitmap;
      //将pStatic指向要显示的地方
      CStatic *pStatic;
      pStatic=(CStatic*)GetDlgItem(IDC_STATIC); //IDC_STATIC是你的Staic控件名
      //装载图片文件MM.bmp
      hbitmap=(HBITMAP)::LoadImage(::AfxGetInstanceHandle(),"MM.bmp",IMAGE_BITMAP,0,0,LR_LOADFROMFILE|LR_CREATEDIBSECTION);
      hbmp.Attach(hbitmap);
    mfc里bitmap 几种加载方式_第2张图片
  3.   
    mfc里bitmap 几种加载方式_第3张图片


  4. 3  //获取图片格式
      BITMAP bm;
      hbmp.GetBitmap(&bm);
      CDC dcMem;
      dcMem.CreateCompatibleDC(GetDC());
      CBitmap * poldBitmap=(CBitmap*)dcMem.SelectObject(hbmp);
      CRect lRect;
      pStatic->GetClientRect(&lRect);
      lRect.NormalizeRect();
      //显示位图
      pStatic->GetDC()->StretchBlt(lRect.left,lRect.top,lRect.Width(),lRect.Height(),&dcMem,0,0,bm.bmWidth,bm.bmHeight,SRCCOPY);
      dcMem.SelectObject(&poldBitmap);

你可能感兴趣的:(mfc里bitmap 几种加载方式)