如何在MFC对话框Picture control里面显示指定路径的图片?
1个回答
展开全部
下面的代码把路径和控件ID替换一下就能用了
IPicture *m_picture;
OLE_XSIZE_HIMETRIC m_width;
OLE_YSIZE_HIMETRIC m_height;
CString m_filename(cFilePath);//读取的文件名
CFile m_file(m_filename,CFile::modeRead );
//获取文件长度
DWORD m_filelen = m_file.GetLength();
//在堆上分配空间
HGLOBAL m_hglobal = GlobalAlloc(GMEM_MOVEABLE,m_filelen);
LPVOID pvdata = NULL;
//锁定堆空间,获取指向堆空间的指针
pvdata = GlobalLock(m_hglobal);
//将文件数据读区到堆中
m_file.Read(pvdata,m_filelen);
IStream* m_stream;
GlobalUnlock(m_hglobal);
//在堆中创建流对象
CreateStreamOnHGlobal(m_hglobal,TRUE,&m_stream);
//利用流加载图像
OleLoadPicture(m_stream,m_filelen,TRUE,IID_IPicture,(LPVOID*)&m_picture);
m_picture->get_Width(&m_width);
m_picture->get_Height(&m_height);
CDC* dc = GetDC();
//在控件范围显示图片
CRect rect;
GetDlgItem(IDC_STATIC_PREVIEW)-> GetWindowRect(&rect);
ScreenToClient(&rect);
m_picture->Render(*dc,rect.left,rect.top,rect.Width(),rect.Height(),0,m_height,m_width,-m_height,NULL);
m_picture->Release();
IPicture *m_picture;
OLE_XSIZE_HIMETRIC m_width;
OLE_YSIZE_HIMETRIC m_height;
CString m_filename(cFilePath);//读取的文件名
CFile m_file(m_filename,CFile::modeRead );
//获取文件长度
DWORD m_filelen = m_file.GetLength();
//在堆上分配空间
HGLOBAL m_hglobal = GlobalAlloc(GMEM_MOVEABLE,m_filelen);
LPVOID pvdata = NULL;
//锁定堆空间,获取指向堆空间的指针
pvdata = GlobalLock(m_hglobal);
//将文件数据读区到堆中
m_file.Read(pvdata,m_filelen);
IStream* m_stream;
GlobalUnlock(m_hglobal);
//在堆中创建流对象
CreateStreamOnHGlobal(m_hglobal,TRUE,&m_stream);
//利用流加载图像
OleLoadPicture(m_stream,m_filelen,TRUE,IID_IPicture,(LPVOID*)&m_picture);
m_picture->get_Width(&m_width);
m_picture->get_Height(&m_height);
CDC* dc = GetDC();
//在控件范围显示图片
CRect rect;
GetDlgItem(IDC_STATIC_PREVIEW)-> GetWindowRect(&rect);
ScreenToClient(&rect);
m_picture->Render(*dc,rect.left,rect.top,rect.Width(),rect.Height(),0,m_height,m_width,-m_height,NULL);
m_picture->Release();
追问
给你吧,虽然我之前已经解决了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询