MFC/QTコントロールに画像をリアルタイムで表示

1302 ワード

//----------MFC      -------------------
void ShowImage(IplImage* img, UINT ID) // picture          
{
  CDC* pDC=GetDlgItem(ID)->GetDC();
  HDC hDC=pDC->GetSafeHdc();
  CRect rect;
  GetDlgItem(ID)->GetClientRect(&rect);
  SetRect(rect,rect.left,rect.top,rect.right,rect.bottom);
  CvvImage cimg;
  cimg.CopyOf( img ); //     
  cimg.DrawToHDC( hDC, &rect );  //                 
  ReleaseDC( pDC );
}

//---------QT      -------------------------
void resizeEvent(QResizeEvent * event)
{
	QFrame::resizeEvent(event);

	QSize size = m_imageLable->size();
	SetWindowExtents(m_halWnd,0,0,size.width(),size.height());
}

void initHalWnd()
{
	QSize size = m_imageLable->size();
	
	HWND parent = (HWND)m_imageLable->winId();
	OpenWindow(0,0,size.width(),size.height(),(Hlong)parent,"","",&m_halWnd);
}

void onGrab()
{
	QHCamera * cam = getCurCamera();
	if(cam)
	{	
		cam->grab(&m_image);
		DispObj(m_image,m_halWnd);
	}
}