/// <summary> /// Captures the currently displayed video image and returns a GDI bitmap. /// </summary> /// <returns>The GDI bitmap copied from the video renderer.</returns> public ConfiguredTaskAwaitable <Bitmap> CaptureBitmapAsync() => Task.Run(async() => { Bitmap retrievedBitmap = null; // Since VideoView might be hosted on a different dispatcher, // we use the custom InvokeAsync method await VideoView?.InvokeAsync(() => { var source = VideoView?.Source?.Clone() as BitmapSource; if (source == null) { return; } source.Freeze(); var encoder = new BmpBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(source)); var stream = new MemoryStream(); encoder.Save(stream); stream.Position = 0; retrievedBitmap = new Bitmap(stream); }); return(retrievedBitmap); }).ConfigureAwait(true);