Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do you capture current frame from a MediaElement in WinRT (8.1)?
    primarykey
    data
    text
    <p>I am trying to implement a screenshot functionality in a WinRT app that shows Video via a MediaElement. I have the following code, it saves a screenshot that's the size of the MediaElement but the image is empty (completely black). Tried with various types of Media files. If I do a Win Key + Vol Down on Surface RT, the screen shot includes the Media frame content, but if I use the following code, it's blackness all around :(</p> <pre><code>private async Task SaveCurrentFrame() { RenderTargetBitmap renderTargetBitmap = new RenderTargetBitmap(); await renderTargetBitmap.RenderAsync(Player); var pixelBuffer = await renderTargetBitmap.GetPixelsAsync(); MultimediaItem currentItem = (MultimediaItem)this.DefaultViewModel["Group"]; StorageFolder currentFolder = Windows.Storage.ApplicationData.Current.LocalFolder; var saveFile = await currentFolder.CreateFileAsync(currentItem.UniqueId + ".png", CreationCollisionOption.ReplaceExisting); if (saveFile == null) return; // Encode the image to the selected file on disk using (var fileStream = await saveFile.OpenAsync(FileAccessMode.ReadWrite)) { var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.PngEncoderId, fileStream); encoder.SetPixelData( BitmapPixelFormat.Bgra8, BitmapAlphaMode.Ignore, (uint)renderTargetBitmap.PixelWidth, (uint)renderTargetBitmap.PixelHeight, DisplayInformation.GetForCurrentView().LogicalDpi, DisplayInformation.GetForCurrentView().LogicalDpi, pixelBuffer.ToArray()); await encoder.FlushAsync(); } } </code></pre> <p>Here MultimediaItem is my View Model class that among other things has a UniqueId property that's a string.</p> <p>'Player' is the name of the Media Element.</p> <p>Is there anything wrong with the code or this approach is wrong and I've to get in the trenches with C++?</p> <p>P.S. I am interested in the WinRT API only.</p> <p><strong>Update 1</strong> Looks like RenderTargetBitmap doesn't support this, the MSDN documentation clarifies it <a href="http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.rendertargetbitmap" rel="nofollow">http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.rendertargetbitmap</a> . I'll appreciate any pointers on how to do it using DirectX C++. This is a major task for me so I'll crack this one way or the other and report back with the solution.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload