/// <summary> /// 鼠标在空间窗体里滑动,显示鼠标所在位置的灰度值 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void HWindowControl_HMouseMove(object sender, HMouseEventArgs e) { if (hv_image != null) { try { int button_state; double positionX, positionY; string str_value; string str_position; bool _isXOut = true, _isYOut = true; HTuple channel_count; HOperatorSet.CountChannels(hv_image, out channel_count); hv_window.GetMpositionSubPix(out positionY, out positionX, out button_state); str_position = String.Format("RC: {0:0000},{1:0000}", positionY, positionX); _isXOut = (positionX < 0 || positionX >= hv_imageWidth); _isYOut = (positionY < 0 || positionY >= hv_imageHeight); if (!_isXOut && !_isYOut) { if ((int)channel_count == 1) { double grayVal; grayVal = hv_image.GetGrayval((int)positionY, (int)positionX); str_value = String.Format("Val: {0:000}", grayVal); } else if ((int)channel_count == 3) { double grayValRed, grayValGreen, grayValBlue; HImage _RedChannel, _GreenChannel, _BlueChannel; _RedChannel = hv_image.AccessChannel(1); _GreenChannel = hv_image.AccessChannel(2); _BlueChannel = hv_image.AccessChannel(3); grayValRed = _RedChannel.GetGrayval((int)positionY, (int)positionX); grayValGreen = _GreenChannel.GetGrayval((int)positionY, (int)positionX); grayValBlue = _BlueChannel.GetGrayval((int)positionY, (int)positionX); _RedChannel.Dispose(); _GreenChannel.Dispose(); _BlueChannel.Dispose(); str_value = String.Format("Gray: ({0:000}, {1:000}, {2:000})", grayValRed, grayValGreen, grayValBlue); } else { str_value = ""; } m_CtrlHStatusLabelCtrl.Text = string.Format("Ch:{0} ", channel_count.ToDArr()) + str_imgSize + " " + str_position + " " + str_value; } } catch (Exception ex) { //不处理 } } }