wordpress   发布时间:2022-04-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了windows – 如何获取MediaCapture的预览缓冲区 – 通用应用程序大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_696_3@概述 在Windows手机silverlight中,我在启动预览视频时使用PhotoCamera获取缓冲帧,在通用应用中我使用MediaCapture,但我不知道如何获取预览缓冲区. 谢谢 由于Windows Runtime没有Silverlight的PhotoCaptureDevice类,因此无法使用非常有用的GetPreviewBufferARGB()和GetPreviewBufferYCbCr()
在Windows手机silverlight中,我在启动预览视频时使用PhotoCamera获取缓冲帧,在通用应用中我使用MediaCapture,但我不知道如何获取预览缓冲区.

谢谢

由于Windows Runtime没有Silverlight的PhotoCaptureDevice类,因此无法使用非常有用的GetPreviewBufferARGB()和GetPreviewBufferYCbCr()方法.

您正在寻找的解决方案是使用MediaCapture.StartPreviewToCustomSinkAsync()方法,但这需要比我的技能更好的C技能.没有人似乎已经解决了问题并分享了他们的代码.

现在有一个非常漂亮的解决方案,使用Lumia Imaging SDK,不使用MediaCapture类,但可能会更好地解决您的问题.

首先查看Microsoft的example on Github.这很好用但很复杂,因为它同时针对Windows 8.1和Windows Phone 8.1.

为了我自己的理解,我已经编写了一些更简单的代码,仅针对Windows Phone.它可能有所帮助.

首先使用通过NuGet PM安装Lumia Imaging SDK的新C#Windows Phone 8.1(StorE)应用程序.此示例在MainPage.xaml中使用X:Name =“previewImage”绘制到图像元素,因此请确保添加该元素.你还需要对MainPage.xaml.cs进行相关的导入.

@H_450_31@using Lumia.Imaging; using System.Threading.Tasks; using WindowS.UI.Xaml.Media.Imaging; using WindowS.UI.Core; using System.ComponentModel;

然后,您只需在MainPage.xaml.cs中的正确位置添加以下内容.

@H_450_31@private CameraPreviewImagesource _cameraPreviewImagesource; // Using camera as our image source private WriteableBitmap _writeableBitmap; private FilterEffect _effect; private WriteableBitmapRenderer _writeableBitmapRenderer; // renderer for our images private bool _isRendering = false; // Used to prevent multiple renderers running at once public MainPage() { this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.required; startCameraPreview(); } private async Task startCameraPreview() { // Create a camera preview image source (from the Lumia Imaging SDK) _cameraPreviewImagesource = new CameraPreviewImagesource(); await _cameraPreviewImagesource.InitializeAsync(String.Empty); // use the first available camera (ask me if you want code to access other camera) var previewProperties = await _cameraPreviewImagesource.StartPreviewAsync(); _cameraPreviewImagesource.PreviewFrameAvailable += drawPreview; // call the drawPreview method every time a new frame is available // Create a preview bitmap with the correct aspect ratio using the properties object returned when the preview started. var width = 640.0; var height = (width / previewProperties.Width) * previewProperties.Height; var bitmap = new WriteableBitmap((int)width,(int)height); _writeableBitmap = bitmap; // Create a BitmapRenderer to turn the preview Image sourcE into a bitmap we hold in the PreviewBitmap object _effect = new FilterEffect(_cameraPreviewImagesourcE); _effect.Filters = new IFilter[0]; // null filter for Now _writeableBitmapRenderer = new WriteableBitmapRenderer(_effect,_writeableBitmap); } private async void drawPreview(IImageSize args) { // Prevent multiple rendering attempts at once if (_isRendering == falsE) { _isRendering = true; await _writeableBitmapRenderer.RenderAsync(); // Render the image (with no filter) // Draw the image onto the previewImage XAML element await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoredispatcherPriority.High,() => { previewImage.source = _writeableBitmap; // previewImage is an image element in MainPage.xaml _writeableBitmap.Invalidate(); // force the PreviewBitmap to redraw }); _isRendering = false; } }

你可能想知道……我怎么抓住previewBuffer?你不需要!

_writeableBitmap对象始终保存来自摄像头的最新帧,因此您可以随意执行任何操作.

大佬总结

以上是大佬教程为你收集整理的windows – 如何获取MediaCapture的预览缓冲区 – 通用应用程序全部内容,希望文章能够帮你解决windows – 如何获取MediaCapture的预览缓冲区 – 通用应用程序所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。