如何在wpf中获取控件的图像 [英] How to take the image of a control in wpf

查看:253
本文介绍了如何在wpf中获取控件的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击一个按钮并将该图像保存为.jpeg图像文件时,我想在wpf中获取控件的图像(可以是任何控件,如文本框或网格等..)。我想要控件的确切图像,我的意思是里面的大小和内容。我正在使用c#语言。任何人请帮助我。

提前谢谢

解决方案

查看 System.Windows.Media.Imaging.RenderTargetBitmap

创建 RenderTargetBitmap 适当的大小等。

调用该 .Render(...)方法> RenderTargetBitmap 传递WPF控件(实际上,从 System.Windows.Media.Visual 派生的任何东西)。

然后调用位图的 .Freeze()方法。

转换为JPEG。



有关更多信息,请使用此搜索CodeProject for R enderTargetBitmap和jpeg [ ^ ]

I want to take the image of a control(it can be any control,like a textbox or a grid etc..) in wpf when i clicks a button and save that image as a .jpeg image file.I wants the exact image of the control,i mean the size and the contents inside.I'm using c# language.Any one please helps me.
Thanks in advance

解决方案

Look at System.Windows.Media.Imaging.RenderTargetBitmap.
Create a RenderTargetBitmap of the appropriate size, etc.
Call the .Render(...) method of that RenderTargetBitmap passing the WPF control (actually, anything derived from System.Windows.Media.Visual).
Then call the .Freeze() method of the bitmap.
Convert to JPEG.

For more information, use this search of CodeProject for RenderTargetBitmap and jpeg [^]


这篇关于如何在wpf中获取控件的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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