Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在WPF桌面应用程序中使用WinRT MediaCapture录制时使用CapturedFrame呈现网络摄像机视频预览_C#_Wpf_Xaml_Video_Windows Runtime - Fatal编程技术网

C# 如何在WPF桌面应用程序中使用WinRT MediaCapture录制时使用CapturedFrame呈现网络摄像机视频预览

C# 如何在WPF桌面应用程序中使用WinRT MediaCapture录制时使用CapturedFrame呈现网络摄像机视频预览,c#,wpf,xaml,video,windows-runtime,C#,Wpf,Xaml,Video,Windows Runtime,有很多开发人员对MediaCapture类可以在WPF中使用感到沮丧,但是,用于预览视频录制的CaptureElement不可用 我理解这个限制,但是,我想使用MediaCapture类来录制视频。。如果可能的话,我想找到一种在WPF中提供预览的方法 在网上进行了大量挖掘之后,我偶然发现了CapturedFrame类。CapturedFrame似乎是一个抽象,表示从MediaCapture对象录制的单个视频帧 CapturedFrame MSDN: CapturedFrame类具有属性Soft

有很多开发人员对MediaCapture类可以在WPF中使用感到沮丧,但是,用于预览视频录制的CaptureElement不可用

我理解这个限制,但是,我想使用MediaCapture类来录制视频。。如果可能的话,我想找到一种在WPF中提供预览的方法

在网上进行了大量挖掘之后,我偶然发现了CapturedFrame类。CapturedFrame似乎是一个抽象,表示从MediaCapture对象录制的单个视频帧

CapturedFrame MSDN:

CapturedFrame类具有属性SoftwareBitmap

我的问题:

有人能提供一些代码或链接来演示如何从MediaCapture将视频录制到文件中吗。。在处理每个帧时,如何使用图像控件抓取位图以在WPF中显示位图

我知道这不是处理问题的最有效的方法,但是,如果这是可能的并且确实有效,那么对于我们所有不能使用CaptureElement的WPF桌面开发人员来说,这应该是一个可行的解决方法

我想说的是,我知道WPFMediaKit和其他开源项目,但是,如果这是可能的,这就是我希望继续进行的方式


提前感谢您的回复。

Microsoft github页面上有一个相关示例,尽管它们针对的是Windows 10应用商店应用程序。如果我要开始一个新项目,我会使用通用Windows平台而不是WPF,因此您可能会对迁移项目以获得此功能和其他功能感兴趣

:此示例将捕获软件位图的预览帧,并将其显示在图像控件中。以下是相关部分:

private async Task GetPreviewFrameAsSoftwareBitmapAsync()
{
    // Get information about the preview
    var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties;

    // Create the video frame to request a SoftwareBitmap preview frame
    var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height);

    // Capture the preview frame
    using (var currentFrame = await _mediaCapture.GetPreviewFrameAsync(videoFrame))
    {
        // Collect the resulting frame
        SoftwareBitmap previewFrame = currentFrame.SoftwareBitmap;

        // Copy the SoftwareBitmap to a WriteableBitmap to display it to the user
        var wb = new WriteableBitmap(previewFrame.PixelWidth, previewFrame.PixelHeight);
        previewFrame.CopyToBuffer(wb.PixelBuffer);

        // Display it in the Image control
        PreviewFrameImage.Source = wb;
    }
}
仔细查看示例,了解如何获取所有细节。或者,要进行演练,您可以从最近的//构建/会议中观看,其中包括一些摄影机示例的演练


现在,如果您确实迁移了您的项目,您也可以使用CaptureElement,但我认为您可能会有兴趣看到这一点。

Mike,谢谢您的代码。我正在尝试测试代码,但无法从我的WPF应用程序中引用访问视频帧和软件位图类型。在这一点上,迁移到通用应用程序在我的情况下是不可能的(因此我的问题…)。。视频帧和软件位图可以在WPF(桌面)中使用吗?如果是,是否有其他我需要引用的程序集?以下是到目前为止的参考资料:System.Runtime.dll System.Runtime.InteropServices.WindowsRuntime.dll System.Runtime.WindowsRuntime.dll我可以毫无问题地使用MediaCapture。有什么想法吗?是的,我想它在WPF中不可用。但您可能想看看其他人是如何解决这个问题的:当我查看有关VideoFrame和SoftwareBitmap的MSDN文档时,该文档较新(适用于Windows 10),并且没有指定是否仅在桌面/Metro或Metro上支持它的prereq注释。有人知道VideoFrame和SoftwareBitamp是否是桌面上最受支持的类型吗?我认为它们只适用于现代/商店应用程序。很抱歉我希望看到此示例的Windows 8版本。