我正在尝试打开前置摄像头,但它打开默认后置摄像头。请建议我如何实现这一点?
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/