【发布时间】:2013-10-18 14:56:43
【问题描述】:
如何获取使用 USB(网络摄像头)连接到我的 PC 的所有摄像头设备的列表,以及笔记本电脑具有的内置摄像头。
【问题讨论】:
标签: c# windows video-camera
如何获取使用 USB(网络摄像头)连接到我的 PC 的所有摄像头设备的列表,以及笔记本电脑具有的内置摄像头。
【问题讨论】:
标签: c# windows video-camera
没有任何外部库的简单解决方案是使用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;
}
【讨论】:
我以前做过 - 使用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...
}
【讨论】: