gpt4 book ai didi

c# - 打开前置摄像头

转载 作者:行者123 更新时间:2023-11-30 17:36:52 25 4
gpt4 key购买 nike

我正在尝试打开前置摄像头,但它打开默认后置摄像头。请建议我如何实现这一点?

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com