海康工业相机 SDK (C# )二次开发 ------- 将图像显示在Halcon的HWindowControl (HSmartWindowControl)上

话不多说,上关键代码!

关键代码一:https://blog.csdn.net/qq_41653486/article/details/103349208 (接前文链接 回调里的GetImageEvent事件)

private void CamsGetImageEvent(object sender, GetImageEventArgs e)
        {
            try
            {
                if (!hikcamera.m_IsConnect)
                    return;

                if (InvokeRequired)
                {
                    IAsyncResult result = BeginInvoke(new HikCameras.OnCamerasGetImageEventHandler(CamsGetImageEvent), sender, e);
                    EndInvoke(result);
                    return;
                }

                ho_Image.GenEmptyObj();
                if (e.IsColor)
                {
                    HOperatorSet.GenImageInterleaved(out ho_Image, e.pImage, "bgr", e.Width, e.Height, 0, "byte", e.Width, e.Height, 0, 0, -1, 0);
                }
                else

                {
                    HOperatorSet.GenImage1(out ho_Image, "byte", e.Width, e.Height, e.pImage);
                }
                HOperatorSet.SetPart(HWC.HalconWindow, 0, 0, e.Height - 1, e.Width - 1);
                HOperatorSet.DispObj(ho_Image, HWC.HalconWindow);
                showMsglb(count++.ToString());
            }
            catch (Exception ex)
            {
                showMsglb("CamsGetImageEvent!" + ex.Message);
            }
        }

 

你可能感兴趣的:(海康相机,Halcon)