void CObjectDetectAndTrackDlg::KShowImage(IplImage *frame, int id)
{
if(frame == NULL)
return;
CvvImage show_image;
show_image.CopyOf(frame);//将frame复制到当前对象中
//m_show_image=temp;
//显示图象
CRect rect;
<span style="background-color: rgb(255, 0, 0);">GetDlgItem(id)</span>->GetClientRect(&rect);//获取picture control的指针,得到区间范围rect
CDC* pDC = GetDlgItem(id)->GetWindowDC();//获取picture control的window指针
pDC->SetStretchBltMode( HALFTONE ); //防止图像缩放失真
show_image.DrawToHDC(pDC->m_hDC,rect);//显示图像
//释放
GetDlgItem(id)->ReleaseDC(pDC);
show_image.Destroy();
}
是的,这样没有任何问题,但是注意的是CObjectDetectAndTrackDlg是继承CDialogEx类的,也算是CWnd类的子类,当然这样直接去使用GetDlgItem(id)没有任何问题,但若不是继承CWnd类,则必须使用sdk中的GetDlgItem(HWND hWnd, IDC_..)。有关GetDlgItem(IDC_..)与GetDlgItem(HWND hWnd, IDC_..)的不同请看这里:http://zhidao.baidu.com/link?url=sw3-yE55qPZLm0CZQVi1VQ3C23oCMsb-7RSHjWTKiZc11gT7_KMhnZ_tZfgFR-oL7gd6PjaqNK1NFZqaLOpMz_ GetDlgItem(IDC_..)的返回值是窗口类指针,而GetDlgItem(HWND hWnd, IDC_..)的返回值是句柄。因此就涉及运用GetDlgItem(HWND hWnd, IDC_..)得到GetDlgItem(IDC_..)的问题(重点):
1.首先要有父窗口hWnd. 这个hWnd可以这样得到:HWND Handle = GetDlgItem(AfxGetApp()->GetMainWnd()->GetSafeHwnd(),id);//获取窗口主句柄 这样就能够获取我们应用的主窗口句柄了
2.由句柄获得该句柄所对应的窗口类:CWnd *hwnd = CWnd::FromHandle(Handle); 其中两者之间的转换可以参考这里:http://blog.sina.com.cn/s/blog_ad0672d601017qp9.html
3.剩下的就能够开心显示图像啦~
void KShowImage(IplImage *frame, int id)
{
if(frame == NULL)
return;
CvvImage show_image;
show_image.CopyOf(frame);//将frame复制到当前对象中
//m_show_image=temp;
//显示图象
CRect rect;
//GetDlgItem(id)->GetClientRect(&rect);//获取picture control的指针,得到区间范围rect
HWND Handle = GetDlgItem(AfxGetApp()->GetMainWnd()->GetSafeHwnd(),id);//获取窗口主句柄
CWnd *hwnd = CWnd::FromHandle(Handle);
hwnd->GetClientRect(&rect);//获取picture control的指针,得到区间范围rect
CDC* pDC = hwnd->GetWindowDC();//获取picture control的window指针
pDC->SetStretchBltMode( HALFTONE ); //防止图像缩放失真
show_image.DrawToHDC(pDC->m_hDC,rect);//显示图像
//释放
hwnd->ReleaseDC(pDC);
show_image.Destroy();
}
好了,第一篇就发到这吧,希望以后进展顺利...