示例#1
0
 public void cameraparamset()
 {
     if (!cameraopen())
     {
         return;
     }
     try { if (exposuretime > 0)
           {
               MvApi.CameraSetExposureTime(m_hCamera, exposuretime);
           }
     } catch { }
     try { if (gain > 0)
           {
               MvApi.CameraSetGain(m_hCamera, Convert.ToInt32(gain / 100), Convert.ToInt32(gain / 100), Convert.ToInt32(gain / 100));
           }
     } catch { }
     try { if (contrast > 0)
           {
               MvApi.CameraSetContrast(m_hCamera, contrast);
           }
     } catch { }
     try { if (gamma > 0)
           {
               MvApi.CameraSetGamma(m_hCamera, Convert.ToInt32(gamma));
           }
     } catch { }
     //try{if (exposuretime > 0) hfg.SetFramegrabberParam("ExposureTime", exposuretime);}catch{}
     //try{if (gain > 0) hfg.SetFramegrabberParam("Gain", gain / 100);}catch{}
     //try{if (contrast > 0) hfg.SetFramegrabberParam("Contrast", contrast);}catch{}
     //try{if (gamma > 0) hfg.SetFramegrabberParam("Gamma", gamma);}catch { }
 }
        //通过滚动条调节伽马
        private void trackBar_Gamma_Scroll(object sender, EventArgs e)
        {
            if (this.ActiveControl != sender)
            {
                return;
            }

            int    gamma  = trackBar_Gamma.Value;
            double fGamma = ((double)gamma) / 100.0;//SDK中伽马的取值范围是0到1000,对应界面上的0到10.0。 1.0的gamma为原始值

            //滚动后更新左边输入框的里值
            textBox_Gamma.Text = fGamma.ToString();

            MvApi.CameraSetGamma(m_hCamera, gamma);
        }
        //通过文本框调节伽马
        private void textBox_Gamma_TextChanged(object sender, EventArgs e)
        {
            if (this.ActiveControl != sender)
            {
                return;
            }

            if (textBox_Gamma.Text == "")
            {
                return;
            }

            double fGamma = Convert.ToDouble(textBox_Gamma.Text);
            int    gamma  = (int)(fGamma * 100.0);//SDK中伽马的取值范围是0到1000,对应界面上的0到10.0。 1.0的gamma为原始值

            trackBar_Contrast.Value = gamma;
            MvApi.CameraSetGamma(m_hCamera, gamma);
        }