我如何使用视频采集设备与DirectX.Capture C#?如何使用、视频采集、设备、Capture

2023-09-05 03:30:36 作者:余生*勿扰

我是新的C#。我不得不创建一个由我的摄像头其备案申请。但我想创建一个摄像头(亮度等)的设置按钮。我有下载这个项目

I am new in C#. I had create an application which record by my webcam. But i want to create a button with the settings of camera(brightness etc). I had download this project

HTTP://www.$c$cproject。 COM /用品/ 3566 / DirectX的捕获级图书馆

要帮助我,但我很困惑。如果你去PropertyPages并单击视频捕获设备,您可以更改摄像头的设置。我无法找到它里面的code我怎么能只使用此窗口。我想点击一个按钮,显示我的设置。

to help me, but i am confused. If you go to PropertyPages and click Video Capture Device you can change the settings of camera. I can't find it inside the code how i could use only this window. I like to click a button and show me the settings.

感谢你在前进,我是新的C#这样不会破坏我的名誉,我知道,我的问题是有点糊涂了,但我很困惑:P!

Thank you in advance, I am new in C# so don't destroy my reputation, i know that my question is a little bit confused but i am confused :P !

推荐答案

与您的疑问,项目的工作流程是这样的:

The workflow of that project related to your question is like this:

在运行应用程序,在菜单中的 updateMenu 方法运行和项目创建的。

When you run the application, the updateMenu method runs and the items in the menu are created.

// 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; }

PropertyPages 是一个属性是第一次被调用时返回 PropertyPageCollection 的名单和每个项目创建菜单。要了解此集合创建外观到属性的身体。并非所有的过滤器图使用的过滤器有PropertyPages。

智能监测系统平台

PropertyPages is a property that first time when is called is returning a list of PropertyPageCollection and for each item is creating a menu. To see how this collection is created look into the property body. Not all the filters used in the filter graph have PropertyPages.

PropertyPageCollection 类接收过滤器和 graphBuilder 。在构造函数中呼吁 addFromGraph 。这种方法会为每个过滤器的 DirectShowPropertyPage ,并将其添加到 InnerList 名单内 PropertyPageCollection 。考虑创建code中的 DirectShowPropertyPage 里面 addIfSupported 方法

The PropertyPageCollectionclass is receiving the filters and the graphBuilder. In the constructor is calling addFromGraph. This method creates for each filter a DirectShowPropertyPage and adds it to the InnerList list inside PropertyPageCollection. The code that is creating the DirectShowPropertyPage is inside addIfSupported method

要显示的属性页此菜单事件挂钩,为筛选器属性页的所有菜单项(见步骤1):

To show the property page this menu event is hooked to all menu items for the filters property pages (see step 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() );
    }
}

该项目正在收集所有你有摄像头。为了达到你的目的,你可以让你自己的方法,并通过视频滤波器(您正在使用的摄像头),过滤器的名称和属性页面(主窗体)的母公司,并直接显示属性页。添加这种方法 Capture.cs 中,添加使用System.Windows.Forms的的情况下,如果缺少参照

This project is collecting all the cameras that you have. To achieve your purpose you can make your own method and pass the video filter (the camera you are using), the name of the filter and the parent of the property page (your main form) and show directly the property page. Add this method in Capture.cs, add the reference to using System.Windows.Forms in case if is missing.

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);
}

呼叫ShowPropertyPage一些按钮的单击事件。你可以通过调用获得使用捕捉类的实例视频滤镜 capture.VideoDevice 和名称 capture.VideoDevice.Name 。当然,首先你要选择相机的工作,也许你需要做一些其他检查。

Call ShowPropertyPage on some button click event. You can get the video filter using the instance of the Capture class by calling capture.VideoDevice and the name capture.VideoDevice.Name. Of course first you have to select the camera to work and maybe you need to do some other checks.

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());
    }
}