MediaCapture StartPreviewAsync fails

為{幸葍}努か 提交于 2019-12-07 22:21:20

问题


I am trying to start video preview capture from the camera in my UWP app but StartPreviewAsync throws an exception

Sample Code:

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

回答1:


This error occurs because currently StartPreviewAsync requires a sink to output frames to. This can be fixed by creating a capture element in xaml to display the frames.

<CaptureElement Name="captureElement"/>

now code can be updated to display the preview to the screen

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

If you want to start the preview without displaying anything to the screen you can create the captureElement in your app logic without adding to the view.

var captureElement = new CaptureElement();


来源:https://stackoverflow.com/questions/34190536/mediacapture-startpreviewasync-fails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!