如何使用directshow断开网络连接 [英] how to disconnect from the webcame using directshow

查看:100
本文介绍了如何使用directshow断开网络连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我正在使用DirectShow.net从webCame中捕获图像,在搜索网页后我得到了这段代码并且工作正常:



查看原始完整代码,请点击以下链接

hello everyone,

I'm using DirectShow.net to capture images from a webCame,after searching the web I got this code and it works fine:

to see the original full code kindly follow the link below

bool SetupGraph()
       {
           int hr;
           try
           {
               hr = capGraph.SetFiltergraph(graphBuilder);
               if (hr < 0)
                   Marshal.ThrowExceptionForHR(hr);

               hr = graphBuilder.AddFilter(capFilter, "Ds.NET Video Capture Device");
               if (hr < 0)
                   Marshal.ThrowExceptionForHR(hr);

               DsUtils.ShowCapPinDialog(capGraph, capFilter, this.Handle);

               AMMediaType media = new AMMediaType();
               media.majorType = MediaType.Video;
               media.subType = MediaSubType.RGB24;
               media.formatType = FormatType.VideoInfo;        // ???
               hr = sampGrabber.SetMediaType(media);
               if (hr < 0)
                   Marshal.ThrowExceptionForHR(hr);

               hr = graphBuilder.AddFilter(baseGrabFlt, "Ds.NET Grabber");
               if (hr < 0)
                   Marshal.ThrowExceptionForHR(hr);

               Guid cat = PinCategory.Preview;
               Guid med = MediaType.Video;
               hr = capGraph.RenderStream(ref cat, ref med, capFilter, null, null); // baseGrabFlt
               if (hr < 0)
                   Marshal.ThrowExceptionForHR(hr);

               cat = PinCategory.Capture;
               med = MediaType.Video;
               hr = capGraph.RenderStream(ref cat, ref med, capFilter, null, baseGrabFlt); // baseGrabFlt
               if (hr < 0)
                   Marshal.ThrowExceptionForHR(hr);

               media = new AMMediaType();
               hr = sampGrabber.GetConnectedMediaType(media);
               if (hr < 0)
                   Marshal.ThrowExceptionForHR(hr);
               if ((media.formatType != FormatType.VideoInfo) || (media.formatPtr == IntPtr.Zero))
                   throw new NotSupportedException("صيغه غير معروفه");

               videoInfoHeader = (VideoInfoHeader)Marshal.PtrToStructure(media.formatPtr, typeof(VideoInfoHeader));
               Marshal.FreeCoTaskMem(media.formatPtr); media.formatPtr = IntPtr.Zero;

               hr = sampGrabber.SetBufferSamples(false);
               if (hr == 0)
                   hr = sampGrabber.SetOneShot(false);
               if (hr == 0)
                   hr = sampGrabber.SetCallback(null, 0);
               if (hr < 0)
                   Marshal.ThrowExceptionForHR(hr);

               return true;
           }
           catch (Exception ee)
           {
               MessageBox.Show(this, "Could not setup graph\r\n" + ee.Message, "DirectShow.NET", MessageBoxButtons.OK, MessageBoxIcon.Stop);
               return false;
           }
       }



我的问题是,当我第二次从另一个表单调用此表单时,它给了我这个错误:当编译器出现在此部分时,值不在预期范围内

hr = capGraph.RenderStream (ref cat,ref med,capFilter,null,null);



实际上我发现当我拔掉网络时问题就消失了身体再次插上它,所以我得出结论,我需要使用代码

拔掉它,所以如果你知道怎么做,或者你有什么好主意请告诉我



您可以访问原始代码

http://www.codeproject.com/script/Content/ViewAssociatedFile.aspx ?RZP =%2FKB%2Fdotnet%2FROTEsys%2Frotesys_src.zip&安培;番= Trac的king.cs& obid = 9401& obtid = 2& ovid = 1 [ ^ ]



谢谢你的时间和耐心


my problem is when I call this form from another form for a second time it gives me this error: "Value does not fall within the expected range" when the compiler comes to this section:
hr = capGraph.RenderStream(ref cat, ref med, capFilter, null, null);

actually i discovered that the problem disappear when I unplug the web-came physically and plug it again, so I concluded that i need to unplug it using code
so please if u know tell me how to do it or if u have any better idea please tell me

you can access the original code on
http://www.codeproject.com/script/Content/ViewAssociatedFile.aspx?rzp=%2FKB%2Fdotnet%2FROTEsys%2Frotesys_src.zip&zep=Tracking.cs&obid=9401&obtid=2&ovid=1[^]

thank you for ur time and patience

推荐答案

我有完全相同的问题,

我还在研究,一旦找到它就会发布解决方案
I having exactly same problem,
I am still researching, will post the solution once i find it


你不需要这样做,我找到了一个更好的库。

这里链接:< br $> b $ b

http ://sites.google.com/site/webcamlibrarydotnet/winfrom-and-csharp-sample-code-and-download [ ^ ]



you ju st需要下载页面底部的文件,然后将DLL添加到您的解决方案中并查看其他文件中的示例以了解如何使用,相信我这是我发现的最简单的库

good运气
you don't need to do this, there is a better library I found.
here the link:

http://sites.google.com/site/webcamlibrarydotnet/winfrom-and-csharp-sample-code-and-download[^]

you just need to download the files in the bottom of the page then add the DLL to your solution and see the example in the other file to know how to use, believe me it's the easiest library I found
good luck


非常简单易用。

不幸的是,我坚持使用DirectShow,

我可以使用网络摄像头组件对于第二个观看者,但主要观众必须使用DS。
that's pretty simple and easy to use.
unfortunately, I am stuck with DirectShow,
I can use the webcam component for the second viewer, but the main viewer has to use DS.


这篇关于如何使用directshow断开网络连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆