在SL应用程序,我可以使用:如何获得应用程序的屏幕截图
var bitmap = new WriteableBitmap(uiElementForViewControl, new TranslateTransform());
但UWP,我怎么做同样的事情?
在SL应用程序,我可以使用:如何获得应用程序的屏幕截图
var bitmap = new WriteableBitmap(uiElementForViewControl, new TranslateTransform());
但UWP,我怎么做同样的事情?
使用RenderTargetBitmap来渲染UIElement(例如您的页面),类似于您的代码片段使用WriteableBitmap,然后使用BitmapEncoder将RenderTargetBitmap的像素编码为jpg或png以保存。
见https://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.media.imaging.rendertargetbitmap.aspx和https://msdn.microsoft.com/en-us/library/windows/apps/mt244351.aspx
随着Control.DrawToBitmap
你可以捕捉一个表单,这是你正在寻找的“应用程序”。
它不工作 – CraigTayor
这确实是不幸的。我自己相信很多年前曾经在Windows Forms应用程序中使用它。我搜索了这个函数,并且确实发现它并不适用于所有事情,并且有很多方法。然而,我将不会发布他们,因为Rob有一个很好的答案来帮助OP。 –
private async Task SaveVisualElementToFile(FrameworkElement element, StorageFile file)
{
var renderTargetBitmap = new RenderTargetBitmap();
await renderTargetBitmap.RenderAsync(element);
var pixels = await renderTargetBitmap.GetPixelsAsync();
using (var fileStream = await file.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,
pixels.ToArray());
await encoder.FlushAsync();
}
}
谢谢你,我明白了。 – CraigTayor