Mewlip 2019-01-02 16:07 采纳率: 0%
浏览 1005

求助!!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条回答 默认 最新

  • 乌里随记 2019-09-15 10:01
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导
  • ¥15 docker模式webrtc-streamer 无法播放公网rtsp
  • ¥15 学不会递归,理解不了汉诺塔参数变化
  • ¥30 软件自定义无线电该怎样使用
  • ¥15 R语言mediation包做中介分析,直接效应和间接效应都很小,为什么?
  • ¥15 Jenkins+k8s部署slave节点offline
  • ¥15 如何实现从tello无人机上获取实时传输的视频流,然后将获取的视频通过yolov5进行检测
  • ¥15 WPF使用Canvas绘制矢量图问题
  • ¥15 用三极管设计一个单管共射放大电路