private void MeasureLine_strip_Click(object sender, EventArgs e) { viewPort.Focus(); #if NativeCode ShowUnit.ShowText(viewPort.HalconWindow, "鼠标点击两个位置后,单击鼠标右键完成。", 20, 20, 20, "green", "window"); #else HWndMessage message = new HWndMessage("鼠标点击两个位置后,单击鼠标右键完成。", 20, 20, 20, "green"); message.DispMessage(viewPort.HalconWindow, "window", 1); #endif inMeasureLine = true; viewPort.ContextMenuStrip = null; double r1, c1, r2, c2; HTuple dd; //获取当前显示信息 HTuple hv_Red = null, hv_Green = null, hv_Blue = null; int hv_lineWidth; HWindow window = viewPort.HalconWindow; window.GetRgb(out hv_Red, out hv_Green, out hv_Blue); hv_lineWidth = (int)window.GetLineWidth(); string hv_Draw = window.GetDraw(); window.SetLineWidth(1); //设置线宽 window.SetLineStyle(new HTuple()); window.SetColor("green"); //画点的颜色 window.DrawLine(out r1, out c1, out r2, out c2); window.DispLine(r1, c1, r2, c2); //恢复窗口显示信息 window.SetRgb(hv_Red, hv_Green, hv_Blue); window.SetLineWidth(hv_lineWidth); window.SetDraw(hv_Draw); HOperatorSet.DistancePp(r1, c1, r2, c2, out dd); double dr = Math.Abs(r2 - r1); double dc = Math.Abs(c2 - c1); MessageBox.Show(string.Format("直线距离{0:f2}px\rx轴距离{1:f2}px\ry轴距离{2:f2}px", dd.D, dc, dr), "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); //hv_MenuStrip.Visible = true; viewPort.ContextMenuStrip = hv_MenuStrip; inMeasureLine = false; Repaint(); }
private void ShowHistogram_strip_Click(object sender, EventArgs e) { viewPort.Focus(); #if NativeCode ShowUnit.ShowText(viewPort.HalconWindow, "鼠标左键点击并拉取矩形区域,鼠标右键完成", 20, 20, 20, "green", "window"); #else HWndMessage message = new HWndMessage("鼠标左键点击并拉取矩形区域,鼠标右键完成", 20, 20, 20, "green"); message.DispMessage(viewPort.HalconWindow, "window", 1); #endif inMeasureLine = true; viewPort.ContextMenuStrip = null; double r1, c1, r2, c2; //HTuple dd; //获取当前显示信息 HTuple hv_Red = null, hv_Green = null, hv_Blue = null; int hv_lineWidth; HWindow window = viewPort.HalconWindow; window.GetRgb(out hv_Red, out hv_Green, out hv_Blue); hv_lineWidth = (int)window.GetLineWidth(); string hv_Draw = window.GetDraw(); window.SetLineWidth(1); //设置线宽 window.SetLineStyle(new HTuple()); window.SetColor("green"); //画点的颜色 window.DrawRectangle1(out r1, out c1, out r2, out c2); window.DispRectangle1(r1, c1, r2, c2); Form frm = new Form(); FunctionPlotUnit pointUnit = new FunctionPlotUnit(); Size size = pointUnit.Size; size.Height = (int)(size.Height + 50); size.Width = (int)(size.Width + 50); frm.Size = size; frm.Controls.Add(pointUnit); pointUnit.Dock = DockStyle.Fill; HTuple grayVals; #if NativeCode grayVals = Wrapper.ShowUnit.GetGrayHisto(viewPort.HalconWindow, new HTuple(r1, c1, r2, c2)); #else grayVals = GetGrayHisto(new HTuple(r1, c1, r2, c2)); #endif pointUnit.SetAxisAdaption(FunctionPlot.AXIS_RANGE_INCREASING); pointUnit.SetLabel("灰度值", "频率"); pointUnit.SetFunctionPlotValue(grayVals); pointUnit.ComputeStatistics(grayVals); frm.ShowDialog(); //window.DrawLine(out r1, out c1, out r2, out c2); //window.DispLine(r1, c1, r2, c2); //恢复窗口显示信息 window.SetRgb(hv_Red, hv_Green, hv_Blue); window.SetLineWidth(hv_lineWidth); window.SetDraw(hv_Draw); //HOperatorSet.DistancePp(r1, c1, r2, c2, out dd); //double dr = Math.Abs(r2 - r1); //double dc = Math.Abs(c2 - c1); //MessageBox.Show(string.Format("直线距离{0:f2}px\rx轴距离{1:f2}px\ry轴距离{2:f2}px", dd.D, dc, dr), "结果", MessageBoxButtons.OK, MessageBoxIcon.Information); //hv_MenuStrip.Visible = true; viewPort.ContextMenuStrip = hv_MenuStrip; inMeasureLine = false; Repaint(); }