打开前脸摄像头

时间:2016-08-09 06:14:38

标签: c# windows-phone-8 windows-phone-8.1 windows-phone

我正在尝试打开前置摄像头,但是它的开启默认后置摄像头。请告诉我如何实现这个目标?

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

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

1 个答案:

答案 0 :(得分:1)

您可以尝试使用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);