如何在Windows 8 Metro风格的应用程序中获取相机?

我正在尝试在Windows 8 metro风格的应用程序中获取相机,以便我可以对其进行一些更改,如增强现实。 我试过但只能找到如何使用CameraCaptureUI()捕获图像。 任何人都可以告诉我如何实现AR的摄像头输入?

您需要做的就是为CaptureFileAsync传入CameraCaptureUIMode.Video。 这是一个样本

CameraCaptureUI dialog = new CameraCaptureUI(); dialog.VideoSettings.Format = CameraCaptureUIVideoFormat.Mp4; StorageFile file = null; file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Video); if (file != null) { IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read); //Do something with the stream } 

编辑:

例如,为了应用效果,您可以使用AddEffectAsync方法。

 mediaCaptureMgr.AddEffectAsync(MediaStreamType.VideoPreview, "Microsoft.Samples.GrayscaleEffect", null); 

GrayScaleEffect的Microsoft Foundation Transform(MFT)实现是[这里]。 1 。 该示例应该允许您创建自己的效果。

我之前在博客上写过这篇文章 。

您需要使用CaptureElement和MediaCapture对象:

 var mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); this.captureElement.Source = mediaCapture; await mediaCapture.StartPreviewAsync();