求助!!mfc和halcon混合编程打开图片,没有报错,可是图片没有显示?

利用mfc的picture control显示一个图片,读取图片等操作利用Halcon完成。
点击显示图片按钮,利用CFileDialog类获取图片路径。
然后用Halcon函数,可是picture control没有反应。

void CMCFLearningCaseDlg::OnBnClickedPictureButton()
{
    // TODO: 在此添加控件通知处理程序代码
    //得到图片文件路径
    TCHAR szFilters[] = _T("图片文件(.bmp .png .jpg)/.bmp;.png;*jpg/All Files (.)/.*||");
    CFileDialog fileDlg(TRUE, NULL, NULL, OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters,NULL);
    CString pathName;
    HImage Image;
    HTuple Width, Height;
    if (fileDlg.DoModal() == IDOK)
    {
        pathName = fileDlg.GetPathName();
    }
    //显示路径
    MessageBox(pathName);

    //CString改成char*
    int len = WideCharToMultiByte(CP_ACP, 0, pathName, -1, NULL, 0, NULL, NULL);
    char *ptxtTemp = new char[len + 1];
    WideCharToMultiByte(CP_ACP, 0, pathName, -1, ptxtTemp, len, NULL, NULL);

    //读取图片
    Image.ReadImage(ptxtTemp);
    //得到图片尺寸
    Image.GetImageSize(&Width, &Height);
    //窗口句柄获取
    HWND hImgWnd = GetDlgItem(IDC_PICTURE_STATIC)->m_hWnd;
    CRect rtWindow;
    GetDlgItem(IDC_PICTURE_STATIC)->GetClientRect(&rtWindow);
    HWindow m_htWindow;
    //打开一个窗口并显示图片
    m_htWindow.OpenWindow(rtWindow.left, rtWindow.top, rtWindow.Height(), rtWindow.Width(), (Hlong)hImgWnd, "visible", "");
    m_htWindow.SetPart(0, 0, Width.I(), Height.I());
    Image.DispImage(m_htWindow);
}

1个回答

HObject m_hoImage;
HTuple width, height;
HTuple m_htWindow;
ReadImage(&m_hoImage, ch);
GetImageSize(m_hoImage, &height, &width);
HWND hImgWnd = GetDlgItem(IDC_PICTURE)->m_hWnd;
CRect rtWindow;
GetDlgItem(IDC_PICTURE)->GetClientRect(&rtWindow);
OpenWindow(rtWindow.left, rtWindow.top, rtWindow.Width(), rtWindow.Height(), (Hlong)hImgWnd, "", "", &m_htWindow);
HDevWindowStack::Push(m_htWindow);
if (HDevWindowStack::IsOpen()) {
DispObj(m_hoImage, HDevWindowStack::GetActive());
}

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问