如何在wpf中获取控件的图像

编程入门 行业动态 更新时间:2024-10-25 20:21:56
本文介绍了如何在wpf中获取控件的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

解决方案

查看 System.Windows.Media.Imaging.RenderTargetBitmap 。 创建 RenderTargetBitmap 适当的大小等。 调用该 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中获取控件的图像

本文发布于:2023-11-05 09:35:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1560482.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控件   图像   如何在   wpf

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!