在WinRT的C#怎么使用RenderTargetBitmap我保存屏幕外XAML树? [英] In WinRT C# how do I save an offscreen XAML tree using RenderTargetBitmap?

查看:243
本文介绍了在WinRT的C#怎么使用RenderTargetBitmap我保存屏幕外XAML树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面的代码抛出从RenderAsync方法的神秘System.ArgumentException值没有在预期范围之内。如果另一方面我的画布是一个可见的XAML树它的作品的一部分。它是不可能使一些XAML未显示在屏幕上。

The following code throws a cryptic System.ArgumentException from the RenderAsync method "Value does not fall within the expected range." If on the other hand my Canvas is part of a visible XAML tree it works. Is it impossible to render some XAML that isn't displayed on screen?

Canvas c = new Canvas();
c.Width = 40;
c.Height = 40;
c.Background = new SolidColorBrush(Color.FromArgb(0xff, 0x80, 0xff, 0x80));

RenderTargetBitmap x = new RenderTargetBitmap();
await x.RenderAsync(c);



我差点以为这个答案会工作,但没有运气,我想这仅适用于WPF:< A HREF =htt​​p://stackoverflow.com/questions/1877115/create-wpf-element-offscreen-and-render-to-bitmap>创建WPF元素屏幕外并呈现为位图

更新:

到目前为止,我的最好的办法是把画布我想处理成当前可见的页面,但把它放在下面通常什么是根的UIElement填满屏幕,所以它不是对用户可见的:

So far my best idea is to put the Canvas I want to render to into the currently visible page but place it beneath what is normally the root UIElement that fills the screen so it isn't visible to the user:

<Grid>
    <Canvas x:Name="HiddenCanvas"/>
    <Grid x:Name="mainElement" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    </Grid>
</Grid>



这是不漂亮,但它似乎工作。让我们来看看,如果任何人都可以做的更好。

It isn't beautiful but it seems to work. Lets see if anyone can do better

推荐答案

WinRTXamlToolkit.Composition 命名空间具有这个扩展工程。只需调用这个方法:

WinRTXamlToolkit.Composition namespace has this extension that works. Just call this method:

await WriteableBitmapRenderExtensions.RenderToPngStream(element);

这篇关于在WinRT的C#怎么使用RenderTargetBitmap我保存屏幕外XAML树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆