【问题标题】:How can I get a list of camera devices from my PC C#如何从我的 PC C# 获取相机设备列表
【发布时间】:2013-10-18 14:56:43
【问题描述】:

如何获取使用 USB(网络摄像头)连接到我的 PC 的所有摄像头设备的列表,以及笔记本电脑具有的内置摄像头。

【问题讨论】:

    标签: c# windows video-camera


    【解决方案1】:

    没有任何外部库的简单解决方案是使用WMI

    添加using System.Management;,然后:

    public static List<string> GetAllConnectedCameras()
    {
        var cameraNames = new List<string>();
        using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')"))
        {
            foreach (var device in searcher.Get())
            {
                cameraNames.Add(device["Caption"].ToString());
            }
        }
    
        return cameraNames;
    }
    

    【讨论】:

    • 这是一个比接受答案更好的解决方案(在接受答案时可能不可用),因为它更通用。谢谢!
    • 这也会得到扫描仪,但这是迄今为止最好的答案
    【解决方案2】:

    我以前做过 - 使用http://directshownet.sourceforge.net/ 为您提供一个体面的.net 接口到 DirectShow,然后您可以使用以下代码:

      DsDevice[] captureDevices;
    
      // Get the set of directshow devices that are video inputs.
      captureDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);    
    
      for (int idx = 0; idx < captureDevices.Length; idx++)
      {
        // Do something with the device here...
      }
    

    【讨论】:

      猜你喜欢
      • 2017-08-09
      • 2022-08-11
      • 1970-01-01
      • 1970-01-01
      • 2017-09-25
      • 2011-02-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多