// private void //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ //---------------------------以下代码匀为了在多核心CPU的系统上提高效率的代码---------------- //---------------------------为了简洁,这代码均放在同一块区域中以方便阅读------------------- //---------------------------代码开始编写时间:2010年1月28日,黄纯得编写-------------------- //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------ #endregion private void StartCapture() { this.CloseCamera(); if (!Monitor.TryEnter(shareImageObject)) { return; } try { CameraSource.DeviceForm form = new CameraSource.DeviceForm(); if (form.ShowDialog() == DialogResult.OK) { //VideoSource.CaptureDevice localSource = new VideoSource.CaptureDevice(); //localSource.VideoSource = form.Device; //videoSource = new CameraSource.Camera(localSource); videoSource = form.Camera; if (videoSource == null) { return; } this.Cursor = Cursors.WaitCursor; videoSource.NewFrame += new EventHandler(this.New_Frame); videoSource.Start(); ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessNewImageThread)); IsCaptureFlag = true; this.Cursor = Cursors.Default; oldTime = DateTime.Now; newTime = DateTime.Now; //StartMultiWorkThreadMode(0); if (HasInterface(videoSource.VideoSource.GetType(), typeof(IFileSource))) { ShowVedioControlForm((IFileSource)videoSource.VideoSource); } } } catch (Exception ex) { MessageBox.Show("StartCapture " + ex.Message.ToString()); } finally { Monitor.Exit(shareImageObject); } }
/// <summary> /// 关闭视频流 /// </summary> private void CloseCamera() { if (videoSource != null) { if (vedioControlForm != null) { if (vedioControlForm.SuspendFlag) { vedioControlForm.SuspendFlag = false; } vedioControlForm.Close(); vedioControlForm.Dispose(); vedioControlForm = null; } videoSource.SignalToStop(); videoSource.WaitForStop(); videoSource = null; IsCaptureFlag = false; exitThreadFlag = true; frameRatioStatusLabel.Text = "Frame: 0"; } }
private void StartCapture() { this.CloseCamera(); if (!Monitor.TryEnter(shareImageObject)) return; try { CameraSource.DeviceForm form = new CameraSource.DeviceForm(); if (form.ShowDialog() == DialogResult.OK) { //VideoSource.CaptureDevice localSource = new VideoSource.CaptureDevice(); //localSource.VideoSource = form.Device; //videoSource = new CameraSource.Camera(localSource); videoSource = form.Camera; if (videoSource == null) return; this.Cursor = Cursors.WaitCursor; videoSource.NewFrame += new EventHandler(this.New_Frame); videoSource.Start(); ThreadPool.QueueUserWorkItem(new WaitCallback(ProcessNewImageThread)); IsCaptureFlag = true; this.Cursor = Cursors.Default; oldTime = DateTime.Now; newTime = DateTime.Now; //StartMultiWorkThreadMode(0); if (HasInterface(videoSource.VideoSource.GetType(), typeof(IFileSource))) { ShowVedioControlForm((IFileSource)videoSource.VideoSource); } } } catch (Exception ex) { MessageBox.Show("StartCapture " + ex.Message.ToString()); } finally { Monitor.Exit(shareImageObject); } }