在 Windows Phone 中将 XAML 转换为图像? [英] Converting XAML into an image in Windows Phone?

查看:29
本文介绍了在 Windows Phone 中将 XAML 转换为图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于 Windows Phone 8,我正在寻找一种将 XAML 转换为图像的方法.那可能吗?我在 XAML 混合元素(如图像等)中制作了一个自定义控件,我想以编程方式截取"并保存它.

For Windows Phone 8, I am looking for a way of converting XAML into an image. Is that possible? I have made a custom control in XAML mixing elements such as images and so forth, that I would like to programmatically "take a screenshot of" and save it.

这样做的原因是我试图以自己的方式自定义锁屏.

The reason for this is that I'm trying to customize the lockscreen in my very own way.

推荐答案

使用 WriteableBitmap 类.

来自 MSDN:

从任何 UIElement 开始生成可视化树的位图快照:

Generate a bitmap snapshot of a visual tree starting from any UIElement:

  • 使用 WriteableBitmap.WriteableBitmap 构建 WriteableBitmap.
  • 要在 UI 中显示图像,请使用 WriteableBitmap 作为图像控件(如 Image)的源,或用作 ImageBrush 的源图像.
  • 如果您想多次渲染位图并将实例重用于其他快照,请使用 Render 方法.您需要在 Render 之后调用 Invalidate 来渲染新图像.
  • 您可以选择通过将转换传递给构造函数来保留 UIElement 上的任何现有 RenderTransform,或者通过传递标识转换或 null 来取消任何现有转换.

这篇关于在 Windows Phone 中将 XAML 转换为图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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