zoukankan      html  css  js  c++  java
  • Opencv在MFC客户端的Picture控件上显示图片

    网上看了部分代码,但是觉得或多或少有些坐标位置上的错误,特别明显是体现在GetWindowRect这个API上,MSDN中说他返回的坐标是以屏幕左上角为基点。所以在对话框中必须先转换成基于客户端的坐标,方法是调用ScreenToClient,然后才能够调用CvvImage::DrawToHDC函数。具体步骤如下

    代码
    typedef struct
    {

        CDlg 
    * pDlg;

    }PARAMETER, 
    *PPARAMETER;

    void ShowImage(IplImage * img, void * p)
    {    
        PPARAMETER param 
    = (PPARAMETER)p;

        CDlg 
    * pDigitDlg = param->pDlg;

        
    //Opencv自带类
        CvvImage cimg;

        cimg.CopyOf(img);

        CDC 
    *pDC = pDigitDlg->GetDC();

        HDC hDC
    =  pDC->GetSafeHdc();

        RECT rect;

        
    //获得picture控件的屏幕坐标,IDC_STATIC_PICTURE是图片控件的ID
        pDigitDlg->GetDlgItem(IDC_STATIC_PICTURE)->GetWindowRect(&rect);

        POINT point;

        point.x 
    = rect.left;

        point.y 
    = rect.top;

        
    //调整屏幕坐标到客户端坐标
        ScreenToClient(pDigitDlg->m_hWnd,&point);

        RECT rect2 
    = rect;

        rect.top 
    = point.y;

        rect.bottom 
    = point.y + (rect2.bottom - rect2.top);

        rect.left 
    = point.x;

        rect.right 
    = point.x + (rect2.right - rect2.left);

        
    //CvvImage::DrawToHDC第二参数需要相对客户端的坐标
        cimg.DrawToHDC(hDC,&rect);  

        pDigitDlg
    ->ReleaseDC(pDC);

        
    //无需显示重绘
        
    //pDigitDlg->InvalidateRect(&rect,TRUE);
        
    //pDigitDlg->UpdateWindow(); 

    }
  • 相关阅读:
    datagrid column width in silverlight.
    Dir你肿么了?是肿了么?越来越大?
    tut12几个简单的帧控制
    CreateThread(), _beginthread()和_beginthreadex()
    windows进程优先级
    Lingo06 Handler
    Lingo13 和Flash交互之getURL
    关于define活生生的SB实例,挂起来
    几个Director/Lingo站
    Lingo02 List
  • 原文地址:https://www.cnblogs.com/aicro/p/1661698.html
Copyright © 2011-2022 走看看