MediaCapture StartPreviewAsync失败

我正在尝试从我的UWP应用程序中的相机开始video预览捕获,但StartPreviewAsync会抛出exception

示例代码:

MediaCapture mc = new MediaCapture(); await mc.InitializeAsync(); await mc.StartPreviewAsync(); 

发生此错误是因为当前StartPreviewAsync需要接收器来输出帧。 这可以通过在xaml中创建捕获元素来显示帧来修复。

  

现在可以更新代码以显示屏幕预览

 MediaCapture mc = new MediaCapture(); await mc.InitializeAsync(); captureElement.Source = mc; await mc.StartPreviewAsync(); 

如果要在不向屏幕显示任何内容的情况下启动预览,可以在应用逻辑中创建captureElement,而无需添加到视图中。

 var captureElement = new CaptureElement();