void ShowHalconImg(HObject hoImg, int picWidth, int picHeight) { if (null == hoImg) { ShowTips("显示Halcon图像失败!图像对象为空"); return; } _imgShowMode = ImgShowMode.halcon; HOperatorSet.SetPart(hcWnd, 0, 0, picHeight - 1, picWidth - 1); // ch: 使图像显示适应窗口大小 || en: Make the image adapt the window size HOperatorSet.DispObj(hoImg, hcWnd); // ch 显示 || en: display if (hoImg == _currHo) { return; } if (_currHo != null) { _currHo.Dispose(); _currHo = null; } _currHo = hoImg; }
/// <summary> /// 开始/停止采集图像 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btGrab_Click(object sender, EventArgs e) { if (null == _cmr) { MessageBox.Show("开始采集失败:相机未设置"); return; } int err = 0; if (_cmr.IsGrabbing) { if (_isAutoGrabRunning) { _StopAutoGrab(); } err = _cmr.StopGrab(); if (0 == err) { ShowTips("相机已停止图像采集"); UpdateSrc2UI(); return; } else { ShowTips("未能停止相机采集,错误信息:" + _cmr.GetErrorInfo(err)); MessageBox.Show("未能停止相机采集,错误信息:" + _cmr.GetErrorInfo(err)); return; } } else { JFCmrTrigMode tm = JFCmrTrigMode.disable; _cmr.GetTrigMode(out tm); if (chkCallBack.Checked) //使用回调函数的方式显示图片 { if (tm == JFCmrTrigMode.disable) { MessageBox.Show("相机当前为禁用触发模式!不能使用回调\n请修改触发模式或取消回调"); return; } _cmr.RegistAcqFrameCallback(_HikFrameCallback); } else { _cmr.RemoveAcqFrameCallback(_HikFrameCallback); } err = _cmr.StartGrab(); if (0 != err) { ShowTips("开启相机采集失败,错误信息:" + _cmr.GetErrorInfo(err)); MessageBox.Show("开启相机采集失败,错误信息:" + _cmr.GetErrorInfo(err)); return; } if (0 == cbImgDispMode.SelectedIndex) { hcWnd.CloseWindow(); if (null != _currHo) { _currHo.Dispose(); _currHo = null; } _imgShowMode = ImgShowMode.sdk; } else if (1 == cbImgDispMode.SelectedIndex) //halcon显示 { hcWnd.OpenWindow(picBox.Location.X, picBox.Location.Y, picBox.Width, picBox.Height, picBox.Handle, "visible", ""); _imgShowMode = ImgShowMode.halcon; if (_currBmp != null) { _currBmp.Dispose(); _currBmp = null; } } else if (2 == cbImgDispMode.SelectedIndex)//bitmap显示 { hcWnd.CloseWindow(); if (null != _currHo) { _currHo.Dispose(); _currHo = null; } _imgShowMode = ImgShowMode.bitmap; } if (chkContinueGrab.Checked) { _StartAutoGrb(); btGrabOne.Enabled = false; btSoftwareTrig.Enabled = false; } else //非连续采图模式 { if (tm == JFCmrTrigMode.disable) { btGrabOne.Enabled = true; btSoftwareTrig.Enabled = false; } else { btGrabOne.Enabled = false; if (tm == JFCmrTrigMode.software) { btSoftwareTrig.Enabled = true; } else { btSoftwareTrig.Enabled = false; } } } ShowTips("相机开始图像采集..."); UpdateSrc2UI(); return; } }