//根据相机的当前参数,刷新界面上控件,做到同步。 public void UpdateControls() { //根据相机描述信息,设定控件的参数调节范围. tSdkCameraCapbility tCameraDeviceInfo; MvApi.CameraGetCapability(m_hCamera, out tCameraDeviceInfo); //获取RGB三个同道的数字增益后更新界面 trackBar_RedGain.SetRange(0, 399); trackBar_GreenGain.SetRange(0, 399); trackBar_BlueGain.SetRange(0, 399); UpdateRgbGainControls(); //饱和度 int saturation = 0; MvApi.CameraGetSaturation(m_hCamera, ref saturation); trackBar4.SetRange(0, 100); trackBar4.Value = saturation; textBox_Saturation.Text = saturation.ToString(); //彩色转黑白模式 uint bEnable = 0; MvApi.CameraGetMonochrome(m_hCamera, ref bEnable); checkBox_MonoMode.Checked = (bEnable == 1?true:false); //反色模式 MvApi.CameraGetInverse(m_hCamera, ref bEnable); checkBox_InverseImage.Checked = (bEnable == 1?true:false); //对比度 int contrast = 0; MvApi.CameraGetContrast(m_hCamera, ref contrast); trackBar_Contrast.SetRange(0, 200); trackBar_Contrast.Value = contrast; textBox_Contrast.Text = contrast.ToString(); //分辨率 comboBox_RresPreset.Items.Clear(); // 填充分辨率列表 tSdkImageResolution[] infos = new tSdkImageResolution[tCameraDeviceInfo.iImageSizeDesc]; IntPtr ptr = tCameraDeviceInfo.pImageSizeDesc; for (int i = 0; i < infos.Length; i++) { infos[i] = (tSdkImageResolution)Marshal.PtrToStructure((IntPtr)((Int64)ptr + i * Marshal.SizeOf(new tSdkImageResolution())), typeof(tSdkImageResolution)); string sDescription = System.Text.Encoding.Default.GetString(infos[i].acDescription); comboBox_RresPreset.Items.Insert(comboBox_RresPreset.Items.Count, sDescription); } //Marshal.FreeHGlobal (ptr); UpdateResolution(); comboBox_RresPreset.SelectedIndex = m_iResolutionIndex; radioButton_ResolutionROI.Checked = !comboBox_RresPreset.Enabled; radioButton_ResolutionPreset.Checked = comboBox_RresPreset.Enabled; MvApi.CameraGetImageResolution(m_hCamera, out m_tRoiResolution); m_tRoiResolution.iIndex = 0xff; //伽马 int gamma = 0; MvApi.CameraGetGamma(m_hCamera, ref gamma); trackBar_Gamma.SetRange(0, 1000); trackBar_Gamma.Value = gamma; double fGamma = (((double)gamma) / 100.0);//为了好理解,界面上1.0对应SDK的伽马值100,表示1倍的意思,伽马为1的时候,是默认值,相当于没有开启伽马校正。 textBox_Gamma.Text = fGamma.ToString(); //锐度 int sharpness = 0; MvApi.CameraGetSharpness(m_hCamera, ref sharpness); trackBar_Sharpness.SetRange(0, 200); trackBar_Sharpness.Value = sharpness; textBox_Sharpness.Text = sharpness.ToString(); //2D降噪 MvApi.CameraGetNoiseFilterState(m_hCamera, ref bEnable); if (bEnable == 1) { checkBox_2DDenoise.Checked = true; } else { checkBox_2DDenoise.Checked = false; } //3D降噪 int bUseWeight; int counts; int iEnable; MvApi.CameraGetDenoise3DParams(m_hCamera, out iEnable, out counts, out bUseWeight, null); //填充列表 comboBox_3DDenoise.Items.Clear(); comboBox_3DDenoise.Items.Insert(comboBox_3DDenoise.Items.Count, "禁用"); int j; for (j = 2; j <= 8; j++) { comboBox_3DDenoise.Items.Insert(comboBox_3DDenoise.Items.Count, j.ToString()); } if (iEnable == 0) { comboBox_3DDenoise.SelectedIndex = 0; } else { comboBox_3DDenoise.SelectedIndex = counts - 1; } //水平镜像 MvApi.CameraGetMirror(m_hCamera, 0, ref bEnable); if (bEnable == 1) { checkBox_HFlip.Checked = true; } else { checkBox_HFlip.Checked = false; } //垂直镜像 MvApi.CameraGetMirror(m_hCamera, 1, ref bEnable); if (bEnable == 1) { checkBox_VFlip.Checked = true; } else { checkBox_VFlip.Checked = false; } //旋转图像 int iRotate; MvApi.CameraGetRotate(m_hCamera, out iRotate); radioButton_Rotate90.Checked = (iRotate == 1 ? true : false); radioButton_Rotate180.Checked = (iRotate == 2 ? true : false); radioButton__Rotate270.Checked = (iRotate == 3 ? true : false); radioButton_Forbbiden.Checked = (iRotate == 0 ? true : false); //图像采集模式 int iGrabMode = 0; MvApi.CameraGetTriggerMode(m_hCamera, ref iGrabMode); comboBox_TriggerMode.Items.Clear(); comboBox_TriggerMode.Items.Insert(comboBox_TriggerMode.Items.Count, "连续采集模式"); comboBox_TriggerMode.Items.Insert(comboBox_TriggerMode.Items.Count, "软触发模式"); comboBox_TriggerMode.Items.Insert(comboBox_TriggerMode.Items.Count, "硬触发模式"); comboBox_TriggerMode.SelectedIndex = iGrabMode; button_SwTrigger.Enabled = (iGrabMode == 1 ? true : false); //外触发信号模式 int iSignalMode = 0; MvApi.CameraGetExtTrigSignalType(m_hCamera, ref iSignalMode); comboBox_ExtSignalMode.Items.Clear(); comboBox_ExtSignalMode.Items.Insert(comboBox_ExtSignalMode.Items.Count, "上升沿触发"); comboBox_ExtSignalMode.Items.Insert(comboBox_ExtSignalMode.Items.Count, "下降沿触发"); comboBox_ExtSignalMode.SelectedIndex = iSignalMode; //外触发信号去抖时间 uint uJitterTime = 0; MvApi.CameraGetExtTrigJitterTime(m_hCamera, ref uJitterTime); textBox_JetterTime.Text = uJitterTime.ToString(); //闪光灯信号模式 int iStrobMode = 0; MvApi.CameraGetStrobeMode(m_hCamera, ref iStrobMode); radioButton_StrobeModeAuto.Checked = (iStrobMode == 0 ? true : false); radioButton_StrobeModeManul.Checked = (iStrobMode == 1 ? true : false); //闪光灯半自动模式下的有效极性 int uPriority = 0; MvApi.CameraGetStrobePolarity(m_hCamera, ref uPriority); comboBox_StrobePriority.Items.Clear(); comboBox_StrobePriority.Items.Insert(comboBox_StrobePriority.Items.Count, "高电平有效"); comboBox_StrobePriority.Items.Insert(comboBox_StrobePriority.Items.Count, "低电平有效"); comboBox_StrobePriority.SelectedIndex = uPriority; //闪光灯半自动模式下的延时时间 uint uDelayTime = 0; MvApi.CameraGetStrobeDelayTime(m_hCamera, ref uDelayTime); textBox_StrobeDelayTime.Text = uDelayTime.ToString(); //闪光灯半自动模式下的脉冲宽度 uint uPluseWidth = 0; MvApi.CameraGetStrobePulseWidth(m_hCamera, ref uPluseWidth); textBox_StrobePulseWidth.Text = uPluseWidth.ToString(); //相机的模拟增益值 trackBar_AnalogGain.SetRange((int)tCameraDeviceInfo.sExposeDesc.uiAnalogGainMin, (int)tCameraDeviceInfo.sExposeDesc.uiAnalogGainMax); //相机的曝光时间 double dCameraExpTimeMin = 0; //最小时间,单位为 double dCameraExpTimeMax = 0; //最大时间 MvApi.CameraGetExposureLineTime(m_hCamera, ref dCameraExpTimeMin); //相机的曝光时间,最小值为一行时间像素。 dCameraExpTimeMax = (dCameraExpTimeMin * (double)tCameraDeviceInfo.sExposeDesc.uiExposeTimeMax); label_ExpMin.Text = "曝光时间最小值:" + dCameraExpTimeMin.ToString() + "微秒"; label_ExpMax.Text = "曝光时间最大值:" + dCameraExpTimeMax.ToString() + "微秒"; uint uState = 0; MvApi.CameraGetAeState(m_hCamera, ref uState); radioButton_AutoExp.Checked = (uState == 1?true:false); radioButton_ManulExp.Checked = (uState == 0 ? true : false); UpdateExpsoureControls(); }