本文介绍了如何使用directshow断开网络连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 我正在使用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 belowbool 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 codeso please if u know tell me how to do it or if u have any better idea please tell meyou can access the original code onhttp://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推荐答案 这篇关于如何使用directshow断开网络连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 07:06