猿问
下载APP

如何在MFC中使用LoadImgae函数?

CBitmap *pOldBmp;
BITMAP bm;
CDC mdc;

m_Bmp->m_hObject = (HBITMAP)::LoadImage(
AfxGetInstanceHandle(),
path, //image路径
IMAGE_BITMAP,
0,
0,
LR_LOADFROMFILE | LR_CREATEDIBSECTION); 

mdc.CreateCompatibleDC(pDC);
pOldBmp = mdc.SelectObject(m_Bmp);
m_Bmp->GetBitmap(&bm);

pDC->StretchBlt( point.x, point.y, imageWH.x, imageWH.y, &mdc, imagePoint.x, imagePoint.y, bm.bmWidth, bm.bmHeight, SRCCOPY);

胡说叔叔
浏览 110回答 2
2回答

慕码人8056858

mfc里导入 图片资源,自动生成一个资源id(自己改名也可以)比如IDB_BITMAP1然后CBitmap bitmap;bitmap.LoadBitmap(IDB_BITMAP1);显示出来的话再接着用dc就可以了-------------那试试这样m_bitmap.m_hObject = (HBITMAP)::LoadImage(AfxGetInstanceHandle(),_T("对应路径...\\bitmap1.bmp"),IMAGE_BITMAP,0, 0,LR_LOADFROMFILE | LR_CREATEDIBSECTION);

扬帆大鱼

CString path=L"c:\\1.bmp";HBITMAP hbitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),path, IMAGE_BITMAP,0,0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);pictureControlID 为图像控件IDCStatic *pStatic=(CStatic *)GetDlgItem(pictureControlID);HBITMAP hbitmap=(HBITMAP)::LoadImage(AfxGetInstanceHandle(),path, IMAGE_BITMAP,0,0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);if(hbitmap!=NULL){CBitmap m_bitmap;m_bitmap.Attach(hbitmap);pStatic->ModifyStyle(0xF,SS_BITMAP|SS_CENTERIMAGE);pStatic->SetBitmap(hbitmap);}
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

R语言
我要回答