怎么将opencv处理图片在已定义好的MFC中显示出来?
和同学合做一个作业他用c++我用opencv将两个功能结合起来出现了问题。视图类voidCImageView::OnFileOpen(){//TODO:在此添加命令处理程...
和同学合做一个作业 他用c++ 我用opencv 将两个功能结合起来出现了问题。
视图类
void CImageView::OnFileOpen()
{
// TODO: 在此添加命令处理程序代码
Invalidate(); //清空
CFileDialog dlg(TRUE);
if(IDOK==dlg.DoModal())
{
CDC *pDC;
pDC=GetDC();
Manage man;
pic_Path=dlg.GetPathName();
man.Show(0,0,pDC,dlg.GetPathName());
ReleaseDC(pDC);
}
}
Manage 类
bool Manage::Show(int x, int y, CDC* pDC, CString strPath)
{
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
if(file.Open(strPath,CFile::modeRead)&&file.GetStatus(strPath,fstatus)&&((cb=fstatus.m_size)!=-1))
{
HGLOBAL hGlobal=GlobalAlloc(GMEM_MOVEABLE,cb); //给图片分配全局内存
LPVOID pvData=NULL;
if(hGlobal!=NULL)
{
pvData=GlobalLock(hGlobal); //锁定内存
if(pvData!=NULL)
{
file.Read(pvData,cb);
GlobalUnlock(hGlobal); //解锁内存
CreateStreamOnHGlobal(hGlobal,TRUE,&pStm); //用全局内存初始化IStream接口指针
}
}
}
else
return false;
IPicture *pPic; //创建一个IPicture接口指针,表示图片对象
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC jpgWidth;
OLE_YSIZE_HIMETRIC jpgHeight;
pPic->get_Width(&jpgWidth); //用接口方法获得图片的宽
pPic->get_Height(&jpgHeight); //用接口方法获得图片的高
double fX,fY;
fX=(double)pDC->GetDeviceCaps(HORZRES)*(double)jpgWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);
fY=(double)pDC->GetDeviceCaps(VERTRES)*(double)jpgHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);
if(FAILED(pPic->Render(*pDC,x,y,(DWORD)fX,(DWORD)fY,0,jpgHeight,jpgWidth,-jpgHeight,NULL)))
{
pPic->Release();
return false;
}
pPic->Release();
}
else
{
return false;
}
return true;
}
怎么将IplImage *imgae 显示到上面定义的MFC视图框中 啊 求指导啊。。。。。。 展开
视图类
void CImageView::OnFileOpen()
{
// TODO: 在此添加命令处理程序代码
Invalidate(); //清空
CFileDialog dlg(TRUE);
if(IDOK==dlg.DoModal())
{
CDC *pDC;
pDC=GetDC();
Manage man;
pic_Path=dlg.GetPathName();
man.Show(0,0,pDC,dlg.GetPathName());
ReleaseDC(pDC);
}
}
Manage 类
bool Manage::Show(int x, int y, CDC* pDC, CString strPath)
{
IStream *pStm;
CFileStatus fstatus;
CFile file;
LONG cb;
if(file.Open(strPath,CFile::modeRead)&&file.GetStatus(strPath,fstatus)&&((cb=fstatus.m_size)!=-1))
{
HGLOBAL hGlobal=GlobalAlloc(GMEM_MOVEABLE,cb); //给图片分配全局内存
LPVOID pvData=NULL;
if(hGlobal!=NULL)
{
pvData=GlobalLock(hGlobal); //锁定内存
if(pvData!=NULL)
{
file.Read(pvData,cb);
GlobalUnlock(hGlobal); //解锁内存
CreateStreamOnHGlobal(hGlobal,TRUE,&pStm); //用全局内存初始化IStream接口指针
}
}
}
else
return false;
IPicture *pPic; //创建一个IPicture接口指针,表示图片对象
if(SUCCEEDED(OleLoadPicture(pStm,fstatus.m_size,TRUE,IID_IPicture,(LPVOID*)&pPic)))
{
OLE_XSIZE_HIMETRIC jpgWidth;
OLE_YSIZE_HIMETRIC jpgHeight;
pPic->get_Width(&jpgWidth); //用接口方法获得图片的宽
pPic->get_Height(&jpgHeight); //用接口方法获得图片的高
double fX,fY;
fX=(double)pDC->GetDeviceCaps(HORZRES)*(double)jpgWidth/((double)pDC->GetDeviceCaps(HORZSIZE)*100.0);
fY=(double)pDC->GetDeviceCaps(VERTRES)*(double)jpgHeight/((double)pDC->GetDeviceCaps(VERTSIZE)*100.0);
if(FAILED(pPic->Render(*pDC,x,y,(DWORD)fX,(DWORD)fY,0,jpgHeight,jpgWidth,-jpgHeight,NULL)))
{
pPic->Release();
return false;
}
pPic->Release();
}
else
{
return false;
}
return true;
}
怎么将IplImage *imgae 显示到上面定义的MFC视图框中 啊 求指导啊。。。。。。 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询