1

In Universal Windows Apps with the following code snippet

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

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

string deviceID = devices[0].Id;

I can get the cameras that are connected to my device. If there is more than one cameras, is there a way to explicitly get the built in camera and not a USB (or bluetooth or anything) connected one?

John Demetriou
  • 4,093
  • 6
  • 52
  • 88
  • Also I noticed we have two tags with the same meaning so I put them both, a moderator should make them as synonyms – John Demetriou Nov 10 '15 at 11:29
  • With WMI without the need for external libraries: https://stackoverflow.com/questions/19452757/how-can-i-get-a-list-of-camera-devices-from-my-pc-c-sharp/62128539#62128539 – Francesco Bonizzi Jun 01 '20 at 08:48

1 Answers1

2

Use the EnclosureLocation.Panel property to determine whether the camera you found is one that is built into the device. If the panel is Unknown, then it is an external camera. Note that there can be more than one built-in camera. (For example, some devices have both a front camera and a rear camera.)

Code inspired by 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.
}
Raymond Chen
  • 44,448
  • 11
  • 96
  • 135