在MFC 的CView中显示IplImage

 

在MFC 的CView中显示IplImage如下:
//在CXXXDoc.cpp中
public:
IplImage* m_curImg;

BOOL CXXXDoc::OnOpenDocument(LPCTSTR lpszPathName)
{
 if (!CDocument::OnOpenDocument(lpszPathName))
  return FALSE;
    // TODO:  在此添加您专用的创建代码
 m_curImg = cvLoadImage((char*)lpszPathName,0); 
 return TRUE;
}

//在CXXXView.h 中
public:
 void ShowIplImage(IplImage* img);

//在CXXXView.cpp中
void CXXXView::ShowIplImage(IplImage* img)
{
 if(img != NULL)
 {

   CDC* pDC = GetDC();
   HDC hDC = pDC->GetSafeHdc();
   CRect r;
   r.SetRect(0 , 0 , img->width , img->height);
   CvImage cvImg;
   cvImg.CopyOf(img);
   cvImg.DrawToHDC(hDC,&r);
   ReleaseDC(pDC);

  }
}

调用方式如下:
void CXXXView::OnDraw(CDC* pDC)
{
  COpenCVTestDoc* pDoc = GetDocument();
  ASSERT_VALID(pDoc);
  if (!pDoc)
  return;
    // TODO: 在此处为本机数据添加绘制代码
   ShowIplImage(pDoc->m_curImg); // 在CXXXDoc.h中定义IplImage* m_curImg;
 }

其中:CvImage类在http://blog.csdn.net/xinzheng_wang/article/details/7556695

 

 

你可能感兴趣的:(null,mfc)