为什么不使用Microsoft® Video for Windows® (VFW) 

解决方案 »

  1.   

    VFW没有用过关键问题不在于我用什么库捕获的,而是如何在Windows Form中显示啊
      

  2.   

    不停保存视频中每一帧的图片,弄一个Timer,不停地加载图片(以较高的频率)。原理, 确实是这样的, 但是在.net里, 简单的Timer难以保证流畅性
      

  3.   

    http://www.cnblogs.com/witluo/articles/540228.html
      

  4.   

    Picture只能一张张的显示图片,效率比较低,用个显示视频的控件吧
      

  5.   

    这个问题我做过,就是到网上下一个microsoft 公司的DirectX 控件,然后找到里面的AudioVideoPlayback.dll;接下来按照平时调用dll的方法就可以用了。这个问题在http://www.qqread.com/csharp/i487113002.html上有很详细的说明!我现在也有做好的程序,如果你需要。可以发邮件给我。[email protected]!
      

  6.   

    在代码生成的picturebox中如何加载图片呢?
    学习
      

  7.   

    代码生成picturebox pb=new picturebox();
    pb.loction=new point(24;58);
    pb.size=new size(100,200);
    pb.image=imagelist1.images[0];
    this.control.add(pb);//pb.image=imagelist1.images[0];
    这句总是提示错误说索引值无效。
    请教 如何应用才能显示图片呢?
      

  8.   

            /// <summary>
            /// 视频按钮功能,打开当前已安装的视频驱动程序,并向远程客户端发送信息,通知视频连接
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void tool_Video_Click(object sender, EventArgs e)
            {
                viodeo = new Video(pictureBox1.Handle, pictureBox1.Width, pictureBox1.Height);    //创建并引用Video类
                viodeo.StartWebCam();                                                             //打开视频设备
                ClassMsg msg = new ClassMsg();
                msg.sendKind = SendKind.SendCommand;
                msg.msgCommand = MsgCommand.VideoOpen;
                msg.Data = Encoding.Unicode.GetBytes("");
                IPAddress ip = IPAddress.Parse(((this.Tag as TreeNode).Tag as ClassUserInfo).userIp);
                string port = Convert.ToString(((this.Tag as TreeNode).Tag as ClassUserInfo).userPort);
                udpsocket.Send(ip,Convert.ToInt32(port),new ClassSerializers().SerializeBinary(msg).ToArray());
                Voiding = true;
                SendViod = false;
                timer1.Enabled = true;
                panel7.Visible = true;
            }        /// <summary>
            /// 以每秒级的速度向远程客户端发送图片,并将图片存储在远程客户端的指定路劲下
            /// </summary>
            /// <param name="sender"></param>
            /// <param name="e"></param>
            private void timer1_Tick(object sender, EventArgs e)
            {
                if(Voiding || !SendViod || pictureBox1.Image != null)
                {
                    SendViod = true;             //视频开启或关闭
                    IPAddress ip = IPAddress.Parse(((this.Tag as TreeNode).Tag as ClassUserInfo).userIp);
                    string port = Convert.ToString(((this.Tag as TreeNode).Tag as ClassUserInfo).userPort);
                    ////string msgid = Guid.NewGuid().ToString();                                  //设置全局唯一标识
                    string revid = ((this.Tag as TreeNode).Tag as ClassUserInfo).userID;       //远程用户ID
                    string sid = Publec_Class.UserID;                                          //当前用户ID                ClassMsg msg = new ClassMsg();
                    msg.sendKind = SendKind.SendCommand;                      //信息发送的类型
                    msg.msgCommand = MsgCommand.Videoing;                     //发送视频中
                    msg.sendState = SendState.Sending;                        //文件正在发送中
                    msg.SID = sid;
                    msg.SIP = msg.GetLocalIP();
                    msg.RID = revid;
                    //msg.msgID = msgid;
                    msg.Data = Encoding.Unicode.GetBytes("");                ClassMsg start = new ClassMsg();
                    start.sendKind = SendKind.SendCommand;                      //信息发送的类型
                    start.msgCommand = MsgCommand.Videoing;                     //发送视频中
                    start.sendState = SendState.Start;                          //文件正在发送中
                    start.SID = sid;
                    start.SIP = msg.GetLocalIP();
                    start.RID = revid;
                    //start.msgID = msgid;
                    start.Data = Encoding.Unicode.GetBytes("");
                    udpsocket.Send(ip,Convert.ToInt32(port),new ClassSerializers().SerializeBinary(start).ToArray());                viodeo.GrabImage(pictureBox1.Handle,"C:\\TempVoid.Bmp");    //将pictureBox1中的图片存入到指定的路径中
                    FileStream stream = File.OpenRead("C:\\TempVoid.Bmp");      //打开已有的文件,以便读取
                    //对stream中的文件进行分流发送
                    int sendlen = 1024;               //设置读取块的大小
                    long sunlen = (stream.Length);    //获取文件的总大小
                    int offest = 0;                   //读取文件的起始位置
                    while(sunlen > 0)
                    {
                        if (sunlen < sendlen)
                            sendlen = Convert.ToInt32(sunlen);
                        byte[] msgdata = new byte[sendlen];
                        stream.Read(msgdata,offest,sendlen);
                        msg.sendState = SendState.Sending;
                        msg.Data = msgdata;
                        udpsocket.Send(ip,Convert.ToInt32(port),new ClassSerializers().SerializeBinary(msg).ToArray());
                        sunlen -= sendlen;
                    }                ClassMsg End = new ClassMsg();
                    End.sendKind = SendKind.SendCommand;                      //信息发送的类型
                    End.msgCommand = MsgCommand.VideoClose;                     //发送视频中
                    End.sendState = SendState.End;                            //文件发送结束
                    End.SID = sid;
                    End.SIP = msg.GetLocalIP();
                    End.RID = revid;
                    //End.msgID = msgid;
                    End.Data = Encoding.Unicode.GetBytes("");
                    stream.Close();
                    udpsocket.Send(ip, Convert.ToInt32(port), new ClassSerializers().SerializeBinary(start).ToArray());
                    SendViod = false;
                }
            }        /// <summary>
            /// 套接字托管
            /// </summary>
            public delegate void DataArrivalDelegate(byte[] Data, IPAddress Ip, int Port);
            private void udpSocket1_DataArrival(byte[] Data, IPAddress Ip, int Port)
            {
                DataArrivalDelegate outDelegate = new DataArrivalDelegate(DataArrival);
                this.BeginInvoke(outDelegate, new object[] {Data,Ip,Port});
            }
            private void DataArrival(byte[] Data, IPAddress Ip, int Port)
            {
                try
                {
                    ClassMsg msg = new ClassSerializers().DeSerializeBinary(new MemoryStream(Data)) as ClassMsg;
                    switch(msg.msgCommand)
                    {
                        //打开视频
                        case MsgCommand.VideoOpen:
                            Voiding = true;
                            SendViod = false;
                            timer1.Enabled = true;
                            panel7.Visible = true;
                            break;
                        //正在视频中
                        case MsgCommand.Videoing:
                            GetVoid(Data, Ip, Port);
                            break;
                        //关闭视频
                        case MsgCommand.VideoClose:
                            Voiding = false;
                            break;
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }        /// <summary>
            /// 接收图片存入到指定的路劲下,并将图片显示在pictureBox2上
            /// </summary>
            private void GetVoid(byte[] Data, IPAddress Ip, int Port)
            {
                ClassMsg msg = (ClassMsg)new ClassSerializers().DeSerializeBinary(new MemoryStream(Data));
                string sid = msg.SID;
                string msgid = msg.msgID;
                switch(msg.msgCommand)      //信息的命令
                {
                    //正在视频中
                    case MsgCommand.Videoing:
                        {
                            switch(msg.sendState)      // 信息的状态
                            {
                                //开始发送视频文件
                                case SendState.Start:
                                    {
                                        FileStream fs = null;
                                        try
                                        {
                                            string FileName = "C:\\Void.bmp";     //设置文件路径
                                            fs = File.Create(FileName);
                                            fs.Write(msg.Data,0,msg.Data.Length);
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.ToString());
                                        }
                                        finally
                                        {
                                            fs.Close();
                                        }                                    
                                    }
                                    break;
                                //正在发送视频文件
                                case SendState.Sending:
                                    {
                                        FileStream fs = null;
                                        try
                                        {
                                            string FileName = "C:\\Void.bmp";
                                            fs = File.OpenWrite(FileName);
                                            fs.Seek(0, SeekOrigin.End);           //将该流的当前位置设为0
                                            fs.Write(msg.Data, 0, msg.Data.Length);
                                        }
                                        catch (Exception ex)
                                        {
                                            MessageBox.Show(ex.ToString());
                                        }
                                        finally
                                        {
                                            fs.Close();
                                        }
                                    }
                                    break;
                                //发送视频文件结束
                                case SendState.End:
                                    {
                                        pictureBox2.Load("C:\\Void.bmp");
                                    }
                                    break;
                            }
                        }
                        break;
                }
            }        private void button_Incepl_Click(object sender, EventArgs e)
            {
                Voiding = false;
                SendViod = true;
                timer1.Enabled = false;
                panel7.Visible = false;
                viodeo.CloseWebcam();
                string dir = System.Environment.CurrentDirectory;
                dir = dir.Substring(0, dir.Length - 9);
                pictureBox1.Load(@"E:\程序\C# 项目开发\MyQQ\MyQQClient\Images\ChatImages\QQ08.jpg");
                pictureBox2.Load(@"E:\程序\C# 项目开发\MyQQ\MyQQClient\Images\ChatImages\QQ12.jpg");
            }
      

  9.   

    看下这个源码demo,C#完全可以搞定了,不需要调用opencv,用PictureBox时实显示视频!!!http://www.codesoso.com/code/Motion_Detection.aspx