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

时间:2015-11-10 11:28:56

标签: c# camera win-universal-app uwp

在具有以下代码段的通用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(或蓝牙或任何东西)连接的摄像头?

1 个答案:

答案 0 :(得分:1)

使用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.
}