MediaCapture StartPreviewAsync失败 [英] MediaCapture StartPreviewAsync fails

查看:375
本文介绍了MediaCapture StartPreviewAsync失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的UWP应用程序中从相机启动视频预览捕获,但StartPreviewAsync会抛出异常

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

示例代码:

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


推荐答案

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

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();

如果您要开始预览而不在屏幕上显示任何内容,可以在应用程序中创建captureElement逻辑而不添加到视图。

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();

这篇关于MediaCapture StartPreviewAsync失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆