本文介绍了如何从文件加载图像使用MFC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的浏览按钮代码是

void CFileOpenDlg::OnBnClickedButton1()
{
 // TODO: Add your control notification handler code here
 CFileDialog dlg(TRUE);
 int result=dlg.DoModal();
 if(result==IDOK)
 {
  path=dlg.GetPathName();
  UpdateData(FALSE);
 }
}

这是从资源加载图片的代码但不适用于从文件加载图像。我知道 LoadImage(); 是用于这个,但如何?如何编辑此代码从文件加载图像。 Plzz帮助.....

and this is the code for loading an image from resource but that does not work for loading an image from file. i know LoadImage(); is used for this but how? how can i edit this code to load image from file. Plzz help.....

void CFileOpenDlg::OnBnClickedButton2()
{
 // TODO: Add your control notification handler code here
CRect r;
CBitmap* m_bitmap;
CDC dc, *pDC;
BITMAP bmp;
m_bitmap = new CBitmap();
m_bitmap->LoadBitmapW(IDB_BITMAP1);
m_bitmap->GetBitmap(&bmp);
pDC = this->GetDC();
dc.CreateCompatibleDC(pDC);
dc.SelectObject(m_bitmap);
pDC->BitBlt(200, 200, bmp.bmWidth, bmp.bmHeight, &dc,0 , 0, SRCCOPY);
m_bitmap->DeleteObject();
m_bitmap->Detach();
}


推荐答案

HANDLE hBitMap = ::LoadImage(0, "c:\\mybmp.bmp",IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
CBitmap bmp;
bmp.Attach((HBITMAP)hBitMap); 

这篇关于如何从文件加载图像使用MFC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 14:33