Aforge视频采集

 /// <summary>
        /// 获取视频采集设备列表
        /// </summary>
        private void GetCameraList()
        {
            try
            {
                videoDeviceCoolection = new FilterInfoCollection(FilterCategory.VideoInputDevice);
                if (videoDeviceCoolection.Count == 0)
                { 
                    throw new ApplicationException();
                }
                DeviceExits = true;
                foreach (FilterInfo item in videoDeviceCoolection)
                {
                    comboBoxDevices.Items.Add(item.Name);
                }
                comboBoxDevices.SelectedIndex = 0;


            }
            catch (ApplicationException)
            {
                DeviceExits = false;
                MessageBox.Show("Not Find VedioDevice!");
            }
            

        }


        /// <summary>
        /// 播放视频帧
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bit =  (Bitmap)eventArgs.Frame.Clone();
            pictureBox1.Image = bit;
            pictureBox1.Refresh();
        }

        /// <summary>
        /// 播放采集的视频
        /// </summary>
        private void PlayVideo()
        {
            videoDevice = new VideoCaptureDevice(videoDeviceCoolection[comboBoxDevices.SelectedIndex].MonikerString);
            videoDevice.NewFrame += new NewFrameEventHandler(video_NewFrame);
            videoDevice.DesiredFrameSize = new Size(pictureBox1.Width,pictureBox1.Height);
            videoDevice.Start();
        }

 

  private void video_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            Bitmap bit = (Bitmap)eventArgs.Frame.Clone();
            Bitmap cloned = (Bitmap)(bit.Clone());
            GC.Collect();
            pictureBox1.Image = bit;
           // Thread resultThread = new Thread(new ThreadStart(GetResult));
            Thread resultThread = new Thread(new ThreadStart(delegate { GetResult(cloned); }));
            resultThread.Start();
            //resultThread.Start((Bitmap)bit.Clone());
            //GetResult(cloned);

            //GetResultDelegate re = GetResult;
            //IAsyncResult result = re.BeginInvoke(cloned, null, null);

            //Thread th = new Thread(new ParameterizedThreadStart(GetResult));
            //th.Start(bit);
        }

 

posted @ 2013-01-22 12:42  louiskoo  阅读(2040)  评论(1编辑  收藏  举报