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(); 

    }
  • 相关阅读:
    Flink Flow
    Excellent JD
    Storm Flow
    Fundmentals in Stream Computing
    SpringBoot
    Generic/Template Programming in Flink
    Talks on C/S
    Thrift-RPC client in Flume
    Aysnc-callback with future in distributed system
    Unity Shader入门教程(二)最基本的Diffuse和Normal样例
  • 原文地址:https://www.cnblogs.com/aicro/p/1661698.html
Copyright © 2011-2022 走看看