我试图用c在uwp应用程序中捕获xaml网格的视频。
我的方法。
1.使用renderTargetBitmap使用renderTargetBitmap.RenderAsync
2.将数据转换为字节数组。
3.创建一个包含字节的图像文件,并使用BitmapEncoder
4.使用MediaClip.CreateFromImageFileAsync
5.将剪辑添加到媒体合成composition.Clips.Add(clip)
6.使用composition.RenderToFileAsync(video);另存为视频
现在这种方法奏效了。
但正如你所想象的,去磁盘保存图像,然后读取它们来创建剪辑,它的慢WWW和帧速率很低。
我正在寻找的东西,避免去磁盘每一个屏幕截图。
RenderTargetBitmap(或IBufferbyte[])转换为MediaClips而不进入磁盘的东西,或某种保存视频的不同方法。
我正在开发全息镜头的超宽带应用程序。

最佳答案

试试这样的:
和你一样。

using (var soft = SoftwareBitmap.CreateCopyFromBuffer(pixels, BitmapPixelFormat.Bgra8, renderTargetBitmap.PixelWidth, renderTargetBitmap.PixelHeight, BitmapAlphaMode.Premultiplied))
{
   CanvasBitmap canvas = CanvasBitmap.CreateFromSoftwareBitmap(CanvasDevice.GetSharedDevice(), soft);

   MediaClip m = MediaClip.CreateFromSurface(canvas, DateTime.Now - previousFrame);
   composition.Clips.Add(m);
}

记住捕获设备丢失异常并创建新设备

08-26 19:10