コード例 #1
0
ファイル: UcRTLoadImg.cs プロジェクト: hejikaigittree/ASMZZZ
 private void UcRTLoadImg_SizeChanged(object sender, EventArgs e)
 {
     _hcWnd.CloseWindow();
     if (picBox.Width > 0 && picBox.Height > 0)
     {
         _hcWnd.OpenWindow(picBox.Location.X, picBox.Location.Y, picBox.Width, picBox.Height, picBox.Handle, "visible", "");
         if (null != _hoImge)
         {
             HTuple hWidth, hHeight;
             HOperatorSet.GetImageSize(_hoImge, out hWidth, out hHeight);
             HOperatorSet.SetPart(_hcWnd, 0, 0, hHeight - 1, hWidth - 1);
             HOperatorSet.DispObj(_hoImge, _hcWnd);
         }
         else
         {
             _hcWnd.ClearWindow();
         }
     }
     //ShowImage(_hoImge);
 }
コード例 #2
0
ファイル: UcCmr.cs プロジェクト: xhyangxianjun/ASMZZZ
        /// <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;
            }
        }