繁体   English   中英

如何将视频捕获设备与DirectX.Capture C#一起使用?

[英]How i can use Video Capture Device with DirectX.Capture C#?

我是C#的新手。 我创建了一个通过网络摄像头记录的应用程序。 但是我想用相机(亮度等)的设置来创建一个按钮。 我已经下载了这个项目

http://www.codeproject.com/Articles/3566/DirectX-Capture-Class-Library

帮助我,但我很困惑。 如果转到PropertyPages并单击“视频捕获设备”,则可以更改摄像机的设置。 我无法在代码内找到仅使用此窗口的方式。 我想单击一个按钮并向我显示设置。

预先谢谢您,我是C#的新手,所以请不要破坏我的声誉,我知道我的问题有点困惑,但是我很困惑:P!

在此处输入图片说明

在此处输入图片说明

与您的问题相关的那个项目的工作流程是这样的:

  1. 运行应用程序时,将运行updateMenu方法,并创建菜单中的项目。

     // Load property pages try { mnuPropertyPages.MenuItems.Clear(); for (int c = 0; c < capture.PropertyPages.Count; c++) { p = capture.PropertyPages[c]; m = new MenuItem(p.Name + "...", new EventHandler(mnuPropertyPages_Click)); mnuPropertyPages.MenuItems.Add(m); } mnuPropertyPages.Enabled = (capture.PropertyPages.Count > 0); } catch { mnuPropertyPages.Enabled = false; } 
  2. PropertyPages是一个属性,首次调用该属性时将返回PropertyPageCollection的列表,并为每个项目创建一个菜单。 若要查看如何创建此集合,请查看属性主体。 并非过滤器图中使用的所有过滤器都具有PropertyPages。

  3. PropertyPageCollection类正在接收过滤器和graphBuilder 在构造函数中调用addFromGraph 此方法为每个过滤器创建一个DirectShowPropertyPage ,并将其添加到PropertyPageCollectionInnerList列表中。 创建DirectShowPropertyPage的代码在addIfSupported方法内部

  4. 要显示属性页,​​此菜单事件已挂接到过滤器属性页的所有菜单项上(请参阅步骤1):

     private void mnuPropertyPages_Click(object sender, System.EventArgs e) { try { MenuItem m = sender as MenuItem; capture.PropertyPages[m.Index].Show( this ); updateMenu(); } catch (Exception ex) { MessageBox.Show( "Unable display property page. Please submit a bug report.\\n\\n" + ex.Message + "\\n\\n" + ex.ToString() ); } } 
  5. 该项目正在收集您拥有的所有摄像机。 为了实现您的目的,您可以制作自己的方法,并传递视频滤镜(您正在使用的相机),滤镜的名称和属性页的父级(您的主窗体),然后直接显示属性页。 Capture.cs添加此方法,添加对using System.Windows.Forms的引用,以防丢失。

     public bool ShowPropertyPage(Control owner ) { object filter = null; Guid cat = PinCategory.Capture; Guid med = MediaType.Interleaved; Guid iid = typeof(IAMStreamConfig).GUID; int hr = graphBuilder.FindInterface( ref cat, ref med, videoDeviceFilter, ref iid, out filter ); if ( hr != 0 ) { med = MediaType.Video ; hr = graphBuilder.FindInterface( ref cat, ref med, videoDeviceFilter, ref iid, out filter ); if ( hr != 0 ) filter = null; } ISpecifyPropertyPages specifyPropertyPages = null; DsCAUUID cauuid = new DsCAUUID(); bool hasPropertyPage = false; // Determine if the object supports the interface // and has at least 1 property page try { specifyPropertyPages = filter as ISpecifyPropertyPages; if (specifyPropertyPages != null) { int hr = specifyPropertyPages.GetPages(out cauuid); if ((hr != 0) || (cauuid.cElems <= 0)) specifyPropertyPages = null; } } finally { if (cauuid.pElems != IntPtr.Zero) Marshal.FreeCoTaskMem(cauuid.pElems); } // Add the page to the internal collection if (specifyPropertyPages != null) { DirectShowPropertyPage p = new DirectShowPropertyPage(videDevice.Name, specifyPropertyPages); p.Show(owner); hasPropertyPage = true; } return (hasPropertyPage); } 
  6. 在某些按钮单击事件上调用ShowPropertyPage。 您可以通过调用capture.VideoDevice和名称capture.VideoDevice.Name来使用Capture类的实例获取视频过滤器。 当然,首先您必须选择要使用的相机,也许您需要做一些其他检查。

     private void btnShowPropertyPages_Click(object sender, System.EventArgs e) { try { if (capture == null) throw new ApplicationException("Please select a video and/or audio device."); capture.ShowPropertyPage(this); } catch (Exception ex) { MessageBox.Show(ex.Message + "\\n\\n" + ex.ToString()); } } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM