/// <summary> /// 在图像中绘制矩形区域 /// </summary> /// <param name="row"></param> /// <param name="column"></param> /// <param name="phi"></param> /// <param name="length1"></param> /// <param name="length2"></param> public void DrawRectangle2(string color, out double row, out double column, out double phi, out double length1, out double length2) { try { Double _row, _column, _phi, _length1, _length2; ShieldMouseEvent(); hWindowControl1.Focus(); hWindowControl1.HalconWindow.SetColor(color); hWindowControl1.HalconWindow.DrawRectangle2(out _row, out _column, out _phi, out _length1, out _length2); HRegion rectangle = new HRegion(); rectangle.GenRectangle2(_row, _column, _phi, _length1, _length2); rectangle.GenContourRegionXld("border").DispObj(hWindowControl1.HalconWindow); // rectangle.DispObj(hWindowControl1.HalconWindow); rectangle.Dispose(); ReloadMouseEvent(); row = _row; column = _column; phi = _phi; length1 = _length1; length2 = _length2; } catch (System.Exception ex) { row = 0.0; column = 0.0; phi = 0.0; length1 = 0.0; length2 = 0.0; status_message.Text = ex.Message; } }
/// <summary> /// 在图像中绘制圆形区域 /// </summary> /// <param name="row"></param> /// <param name="column"></param> /// <param name="radius"></param> public void DrawCircle(string color, out double row, out double column, out double radius) { try { Double _row, _column, _radius; ShieldMouseEvent(); hWindowControl1.Focus(); hWindowControl1.HalconWindow.SetColor(color); hWindowControl1.HalconWindow.DrawCircle(out _row, out _column, out _radius); HRegion circle = new HRegion(); circle.GenCircle(_row, _column, _radius); circle.GenContourRegionXld("border").DispObj(hWindowControl1.HalconWindow); // circle.DispObj(hWindowControl1.HalconWindow); circle.Dispose(); ReloadMouseEvent(); row = _row; column = _column; radius = _radius; } catch (Exception ex) { row = 0.0; column = 0.0; radius = 0.0; status_message.Text = ex.Message; } }
/// <summary> /// 在图像中绘制矩形区域 /// </summary> /// <param name="rowBegin"></param> /// <param name="colBegin"></param> /// <param name="rowEnd"></param> /// <param name="colEnd"></param> public void DrawRectangle1(string color, out double rowBegin, out double colBegin, out double rowEnd, out double colEnd) { try { Double _rowBegin, _colBegin, _rowEnd, _colEnd; ShieldMouseEvent(); hWindowControl1.Focus(); #region 无用代码 //IntPtr handle = (IntPtr)GetFocus(); //if (handle == null) //{ // this.FindForm().KeyPreview = true; //} //else //{ // Control c = Control.FromHandle(handle);//这就是 //} #endregion hWindowControl1.HalconWindow.SetColor(color); hWindowControl1.HalconWindow.DrawRectangle1(out _rowBegin, out _colBegin, out _rowEnd, out _colEnd); // hv_window.SetColor(color); // hv_window.DrawRectangle1(out _rowBegin, out _colBegin, out _rowEnd, out _colEnd); HRegion rectangle = new HRegion(); rectangle.GenRectangle1(_rowBegin, _colBegin, _rowEnd, _colEnd); rectangle.GenContourRegionXld("border").DispObj(hWindowControl1.HalconWindow); // rectangle.DispObj(hWindowControl1.HalconWindow); rectangle.Dispose(); ReloadMouseEvent(); rowBegin = _rowBegin; colBegin = _colBegin; rowEnd = _rowEnd; colEnd = _colEnd; } catch (System.Exception ex) { rowBegin = 0.0; colBegin = 0.0; rowEnd = 0.0; colEnd = 0.0; status_message.Text = ex.Message; } }
/// <summary> /// 在图像中绘制椭圆形区域 /// </summary> /// <param name="row"></param> /// <param name="column"></param> /// <param name="radius"></param> public void DrawEllipse(string color, out double row, out double column, out double phi, out double radius1, out double radius2) { try { Double _row, _column, _phi, _radius1, _radius2; ShieldMouseEvent(); hWindowControl1.Focus(); hWindowControl1.HalconWindow.SetColor(color); hWindowControl1.HalconWindow.DrawEllipse(out _row, out _column, out _phi, out _radius1, out _radius2); HRegion ellipse = new HRegion(); ellipse.GenEllipse(_row, _column, _phi, _radius1, _radius2); ellipse.GenContourRegionXld("border").DispObj(hWindowControl1.HalconWindow); // ellipse.DispObj(hWindowControl1.HalconWindow); ellipse.Dispose(); ReloadMouseEvent(); row = _row; column = _column; phi = _phi; radius1 = _radius1; radius2 = _radius2; } catch (Exception ex) { row = 0.0; column = 0.0; phi = 0.0; radius1 = 0.0; radius2 = 0.0; status_message.Text = ex.Message; } }