当前位置:编程学习 > C#/ASP.NET >>

求助:C# winform开发视频控制出错。

用winform开发视频控制出错,

我是在父窗口找开一个子窗口,在子窗中调用启动视频时,出现:启动摄像头失败:com对象与其基础RCW分开后就不能再使用。

已经困扰一周了。

按钮代码如下:

 private void btStart_Click(object sender, EventArgs e)
        {
            if (this.running == false)
            {
                try
                {
                    this.camwidth = this.pictureBox1.Width;
                    this.camheigh = this.pictureBox1.Height;
                    this.framerate = 10;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("错误的属性:" + ex.Message);
                    return;
                }

                this.cam = new Capture(this.cbDevice.SelectedIndex, this.framerate, this.camwidth, this.camheigh);// 默认第一个摄像头
                try
                {
                    this.cam.Start();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("启动摄像头失败:" + ex.Message);
                    return;
                }
                this.thread = new Thread(this.Caping);

                this.running = true;
                this.thread.Start();
                this.btStart.Text = "停止视频";
            }
            else
            {
                this.camlock.Reset();
                this.running = false;
                //等待线程结束
                if (this.camlock.WaitOne(2000))
                {
                    //释放资源
                    this.cam.Dispose();
                    this.thread = null;
                    this.cam = null;
                    this.btStart.Text = "启动视频";
                    //this.pnAtb.Enabled = true;
                }
                else
                {
                    this.running = true;
                    MessageBox.Show("停止失败");
                }
            }
        }

请高手帮忙指点下,急待中
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,