现在的位置: 首页 > 综合 > 正文

opencv-IplImage结构图像画到HDC上

2013年04月02日 ⁄ 综合 ⁄ 共 783字 ⁄ 字号 评论关闭
Code:
  1. // draw image(IplImage) to hdc   
  2. void DrawPicToHDC(IplImage *img, UINT ID, HWND hwnd)   
  3. {   
  4. // mfc 方法   
  5. // HWND *pDC = GetDlgItem(ID)->GetDC();   
  6. // HDC hDC=  pDC->GetSafeHdc();   
  7. // GetDlgItem(ID)->GetClientRect(&rect);   
  8. // CvvImage cimg;   
  9. // cimg.CopyOf(img);   
  10. //  cimg.DrawToHDC(hDC,&rect);   
  11. // ReleaseDC(hDC);   
  12.   
  13. // win32方法   
  14. // get the  handle of static control id   
  15. HWND  hID= GetDlgItem(hwnd, ID);   
  16.   
  17. // get the hdc of the handle    
  18. HDC hDC = GetDC(hID);   
  19.   
  20. // the rect struct    
  21. RECT rect;   
  22.   
  23. // get the client of the handle set it in the rect   
  24. GetClientRect(hID,&rect);    
  25.   
  26. // a class of image   
  27.  CvvImage cimg;   
  28.   
  29.  // IplImage copy to CvvImage    
  30.  cimg.CopyOf(img);   
  31.   
  32.  // show the IplImage to the hdc   
  33.  cimg.DrawToHDC(hDC,&rect);   
  34.   
  35.  // release dc   
  36.   ReleaseDC(hID, hDC);   
  37. }   
  38.   

 

抱歉!评论已关闭.