我下了断代码 现在可以视频显示图像了, 我想把它进行传输
各位大侠帮我看看这个段代码应该在哪里修改   
  public void InitGraph()
        {
            if (theDevice == null)
                return;            object o;            //Create the Graph
            graphBuilder = (IGraphBuilder) new FilterGraph();

#if DEBUG
            m_rot = new DsROTEntry(graphBuilder);
#endif            //Create the Capture Graph Builder
            ICaptureGraphBuilder2 captureGraphBuilder = null;
            captureGraphBuilder = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();

            //Create the media control for controlling the graph
            mediaControl = (IMediaControl) this.graphBuilder;            // Attach the filter graph to the capture graph
            int hr = captureGraphBuilder.SetFiltergraph(this.graphBuilder);
            DsError.ThrowExceptionForHR(hr);            //Add the Video input device to the graph
            hr = graphBuilder.AddFilter(theDevice, "source filter");
            DsError.ThrowExceptionForHR(hr);            //Add the Video compressor filter to the graph
            if (theCompressor != null)
            {
                hr = graphBuilder.AddFilter(theCompressor, "compressor filter");
                DsError.ThrowExceptionForHR(hr);
            }            //Create the file writer part of the graph. SetOutputFileName does this for us, and returns the mux and sink
            IBaseFilter mux;
            IFileSinkFilter sink;
            hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, textBox1.Text, out mux, out sink);
            DsError.ThrowExceptionForHR(hr);            //Byte[] FileByteArray = new Byte[5000]; //图象文件临时储存Byte数组 
            //Stream StreamObject = DsError.ThrowExceptionForHR(hr); //建立数据流对像 
            ////读取图象文件数据,FileByteArray为数据储存体,0为数据指针位置、FileLnegth为数据长度 
            //StreamObject.Read(FileByteArray, 0, 5000); 
            //Connect the device and compressor to the mux to render the capture part of the graph
            hr = captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, theDevice, theCompressor, mux);
            DsError.ThrowExceptionForHR(hr);            //Render any preview pin of the device
            hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, theDevice, null, null);
            DsError.ThrowExceptionForHR(hr);            tuner = null;
            crossbar = null;            hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMTVTuner).GUID, out o);
            if (hr >= 0)
            {
                tuner = (IAMTVTuner)o;
                o = null;                hr = captureGraphBuilder.FindInterface(null, null, theDevice, typeof(IAMCrossbar).GUID, out o);
                if (hr >= 0)
                {
                    crossbar = (IBaseFilter)o;
                    o = null;
                }
            }

            //get the video window from the graph
            IVideoWindow videoWindow = null;
            videoWindow = (IVideoWindow) graphBuilder;            //Set the owener of the videoWindow to an IntPtr of some sort (the Handle of any control - could be a form / button etc.)
            hr = videoWindow.put_Owner(panel1.Handle);
            DsError.ThrowExceptionForHR(hr);            //Set the style of the video window
            hr = videoWindow.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipChildren);
            DsError.ThrowExceptionForHR(hr);            // Position video window in client rect of main application window
            hr = videoWindow.SetWindowPosition(0, 0, panel1.Width, panel1.Height);
            DsError.ThrowExceptionForHR(hr);            // Make the video window visible
            hr = videoWindow.put_Visible(OABool.True);
            DsError.ThrowExceptionForHR(hr);            Marshal.ReleaseComObject(mux);
            Marshal.ReleaseComObject(sink);
            Marshal.ReleaseComObject(captureGraphBuilder);
        }

解决方案 »

  1.   

    是实时传输?像QQ视频一样的东西?
    如果是这样的话你多了解一下H264编码  跟视频会议一样的
      

  2.   

    给你一点参考资料:
    1、摄像头监控录像源代码 (详细的代码,可以直接使用,也可以拿来学习使用)
    http://download.csdn.net/source/1172325
    2、屏幕录像软件源代码 经典之作 分享
    http://download.csdn.net/source/1387520/
    3、C#摄像头编程代码
    http://download.csdn.net/source/279427
      

  3.   

    先谢谢了,但是我摄像的功能已经解决了, 就是不知道怎么传输,可以不可以提供下这个方面的例题 
    socket 和DirectShow都行。
      

  4.   

    http://www.codeproject.com/info/search.aspx?artkw=Video_Voice_Conferencing&sbo=kw
      

  5.   

    也可以参考这个SDK:http://www.anychat.cn
      

  6.   

    你的theCompressor是Transform Filter吧?
    自定义一Transform Filter,把获取到的数据压缩后,写入到网络流中
      

  7.   

    可以考虑 Socket 编程,客户端向服务器发送图像数据
      

  8.   

    http://blog.csdn.net/anya/archive/2009/07/22/4371256.aspx
      

  9.   

    guohelv0519:
        我已经用Socket的TCP/IP方式进行编码, 但是我不知道在什么地方获取视频流,视频采集我用的是微软avicap32.dll动态库。 我查了它里面的所有函数,好像没有获取视频流的方法,你有这方面的资料吗?
      

  10.   

       AviCapture.SendMessage(this.lwndC, AviCapture.WM_CAP_SET_CALLBACK_VIDEOSTREAM, 0, 0);//注册视频流回调函数
       AviCapture.SendMessage(this.lwndC, AviCapture.WM_CAP_SET_CALLBACK_FRAME, 0, FrameEventHandler);//注册帧回调函数这两个注册视频流 和帧的函数 我如果要使用,要怎么样才能使用?
      

  11.   

    没有用过这个库,在DirectShow下,可以继承一Transform Filter,并实现ISampleGrabber接口,在Transform方法里去处理视频流
    FrameEventHandler,这个委托里,应该传了每一帧视频流数据吧,直接获取这个数据,写入到网络流不行吗?
      

  12.   

    请参考 http://www.codeproject.com/info/search.aspx?artkw=Video_Voice_Conferencing&sbo=kw,相信你一定能够从这里找到答案。