如果连接了多个摄像头,如何获取内置摄像头?

How to get the built in Camera if more than one cameras are connected?

在通用 Windows 具有以下代码段的应用中

var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);

if (devices.Count < 1)
{
     return;
}

string deviceID = devices[0].Id;

我可以获得连接到我的设备的相机。如果有多个摄像头,是否有办法明确获取内置摄像头而不是 USB(或蓝牙或其他)连接的摄像头?

使用 EnclosureLocation.Panel property 确定您找到的摄像头是否是设备内置的摄像头。如果面板是Unknown,那就是外置摄像头。请注意,可以有多个内置摄像头。 (例如,某些设备同时具有前置摄像头和后置摄像头。)

the Camera Starter Kit sample启发的代码:

// Attempt to get the back camera if one is available,
// but use any camera device if not.
var cameraDevice = await FindCameraDeviceByPanelAsync(
                             Windows.Devices.Enumeration.Panel.Back); 

if (cameraDevice == null)
{
    // This device has no camera.
}
else if (cameraDevice.EnclosureLocation == null ||
         cameraDevice.EnclosureLocation.Panel ==
                             Windows.Devices.Enumeration.Panel.Unknown) 
{ 
     // We have an external camera.
}
else
{
     // We have a built-in camera. The location is reported in
     // cameraDevice.EnclosureLocation.Panel.
}