Dev*_*ned -1 c# windows video-camera
如何获取使用 USB(网络摄像头)连接到我的 PC 的所有摄像头设备以及笔记本电脑内置摄像头的列表。
我之前已经这样做过 - 使用http://directshownet.sourceforge.net/为您提供一个不错的 DirectShow .net 接口,然后您可以使用以下代码:
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...
}
Run Code Online (Sandbox Code Playgroud)
一个没有任何外部库的简单解决方案是使用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;
}
Run Code Online (Sandbox Code Playgroud)