MFC/QT 在控件上实时显示图像
更新于2017-09-19 18:43:46
//----------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);
-
}
-
}
点赞
收藏
分享