c# - 打开前置摄像头

标签 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;
}

最佳答案

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

关于c# - 打开前置摄像头,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38843353/

相关文章:

c# - 从 C# 控制 VisualSVN 服务器

c# - RegularExpressionAttribute 行为中的正则表达式

c# - Microsoft Bot Framework 中带有 FormBuilder 的自定义字段

c# - 从通知导航

c# - 如何使用 Windows Phone 8 从 OBD-II 适配器读取/写入数据?

c# - 如何在写入文件之前清除文件

c# - 消息框 asp.net c#

wpf - WP8.1 中的 XAML : Child Element Styles

c# - 如何在应用程序最小化或在后台运行时保持计时器运行(C# Windows 10 通用应用程序)

c# - XamlReader.Load() 编码