示例#1
0
 private void btn_Start_Click(object sender, EventArgs e)
 {
     if (btn_Start.Text == "开始扫码")
     {
         if (DeviceExist)
         {
             //视频捕获设备
             videoSource = new VideoCaptureDevice(videoDevices[comboBox1.SelectedIndex].MonikerString);
             //捕获到新画面时触发
             videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
             //先关一下,下面再打开。避免重复打开的错误
             CloseVideoSource();
             //设置画面大小
             videoSource.DesiredFrameSize = new Size(405, 305);
             //启动视频组件
             videoSource.Start();
             btn_Start.Text = "停止扫码";
             //启动定时解析二维码
             Timer_DecodeImg.Enabled = true;
             //启动绘制视频中的扫描线
             Timer_ViewImg.Enabled = true;
             Timer_DecodeImg.Start();
             Timer_ViewImg.Start();
         }
     }
     else
     {
         CloseVideoSource();
     }
 }
示例#2
0
 /// <summary>
 /// 关闭摄像头组件
 /// </summary>
 private void CloseVideoSource()
 {
     Timer_DecodeImg.Stop();
     Timer_ViewImg.Stop();
     if (!(videoSource == null))
     {
         if (videoSource.IsRunning)
         {
             videoSource.SignalToStop();
             videoSource = null;
         }
     }
 }
示例#3
0
 private void startscan()
 {
     if (DeviceExist)
     {
         //视频捕获设备
         videoSource = new VideoCaptureDevice(videoDevices[camerindex].MonikerString);
         //捕获到新画面时触发
         videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
         //先关一下,下面再打开。避免重复打开的错误
         CloseVideoSource();
         //设置画面大小
         videoSource.DesiredFrameSize = new Size(405, 305);
         //启动视频组件
         videoSource.Start();
         //启动定时解析二维码
         Timer_DecodeImg.Enabled = true;
         //启动绘制视频中的扫描线
         Timer_ViewImg.Enabled = true;
         Timer_DecodeImg.Start();
         Timer_ViewImg.Start();
     }
 }