Silverlight 4 - 渲染UIElement作为图像 [英] Silverlight 4 - Render UIElement as an Image

查看:144
本文介绍了Silverlight 4 - 渲染UIElement作为图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 UIElement ,我希望捕获用户点击按钮时的快照。当用户单击该按钮时,我想获取 UIElement 并将其当前状态加载到Image元素中。如何将 UIElement 呈现为图像

I have a UIElement that I want to capture a snapshot of when a user clicks a button. When a user clicks the button, I want to take the UIElement and load it's current state into an Image element. How do I render a UIElement as an Image?

推荐答案

假设要渲染的 FrameworkElement 命名为 elementToRender ,并且图像要放置渲染输出的位置称为 图像 ,请在按钮的单击处理程序中使用以下代码:

Assuming the FrameworkElement you want to render is named elementToRender and the Image where you want to place the rendered output is called image, use the following code on your button's click handler:

var writeableBitmap = new WriteableBitmap((int)elementToRender.RenderSize.Width, (int)elementToRender.RenderSize.Height);

writeableBitmap.Render(elementToRender, new ScaleTransform() { ScaleX = 1, ScaleY = 1 });
writeableBitmap.Invalidate();

image.Source = writeableBitmap;

这篇关于Silverlight 4 - 渲染UIElement作为图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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