我正在尝试打开前置摄像头,但要打开默认的后置摄像头。请建议我如何实现此目的?

CameraCaptureUI captureUI = new CameraCaptureUI();
captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
StorageFile photo =await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);

if (photo == null)
{
    // User cancelled photo capture
    return;
}

最佳答案

您可以尝试使用MediaCapture类代替CameraCaptureUI:https://msdn.microsoft.com/en-us/library/windows/apps/xaml/dn642092.aspx

您可以使用DeviceInformation类查询可用的摄像机,例如:

  DeviceInformation device = (await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture))
      .FirstOrDefault(d => d.EnclosureLocation != null && d.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front);


如果返回了设备,请在MediaCaptureInitializationSettings类中设置其ID:

MediaCaptureInitializationSettings settings = new MediaCaptureInitializationSettings();
settings.VideoDeviceId = device.Id;

MediaCapture mediaCapture = new MediaCapture();
await mediaCapture.InitializeAsync(settings);

08-26 18:39