MediaElement を介してビデオを表示する WinRT アプリにスクリーンショット機能を実装しようとしています。次のコードがあります。MediaElement のサイズのスクリーンショットを保存しますが、画像は空 (完全に黒) です。さまざまな種類のメディア ファイルで試しました。Surface RT で Win Key + Vol Down を実行すると、スクリーン ショットにメディア フレームのコンテンツが含まれますが、次のコードを使用すると、全体が黒くなります :(
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();
}
}
ここで、MultimediaItem は、特に文字列である UniqueId プロパティを持つビュー モデル クラスです。
「Player」はメディア要素の名前です。
コードに何か問題がありますか、それともこのアプローチが間違っているので、C++ で塹壕に入る必要がありますか?
PS 私は WinRT API のみに興味があります。
Update 1 RenderTargetBitmap はこれをサポートしていないようです。DirectX C++ を使用してそれを行う方法についての指針をいただければ幸いです。これは私にとって大きなタスクなので、何らかの方法で解決し、解決策を報告します。