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);
        }

 

转载于:https://www.cnblogs.com/liuxinls/archive/2013/01/22/2871170.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值