WPF:如何将任何东西保存为图像vb.net [英] WPF: How to save any thing as image vb.net
本文介绍了WPF:如何将任何东西保存为图像vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将具有TRANSPARENT背景的任何控件保存为图像(例如: Inkcanvas
或网格
控件)控件的背景是透明的?我可以在WinForms应用程序中执行此操作,但我不知道它是否在WPF中是可能的
。
____________________________________________________________________________:D :)
How can I save any control as Image (ex: Inkcanvas
or Grid
control) with a TRANSPARENT background if the control''s background was Transparent? I can do it in WinForms Application and I don''t know if it is Possible
in WPF.
____________________________________________________________________________:D :)
<Thanks To="All" Regards="Best"></Thanks>
推荐答案
让我们从最后开始:透明度不会成为问题,因为PNG位图支持透明度: http://en.wikipedia.org/wiki/Portable_Network_Graphics [ ^ ]。
用于渲染像位图上的控件(实际上你可以渲染任何Visual
因此任何控制;请看下面),你需要使用类System.Windows.Media.DrawingVisual
和System.Windows.Media.Imaging.RenderTargetBitmap
:
http:// msdn .microsoft.com / zh-cn / library / system.windows.media.drawingvisual.aspx [ ^ ],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx [< a href =http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspxtarget =_ blanktitle =New Window> ^ ] 。
如果您查看上面引用的DrawingVisual
类的MSDN帮助页面,您将看到用于创建bitma的代码示例p来自System.Windows.Media.Visual
,但对于Visual
类系统使用.Windows.Media.DrawingVisual
,这是你不需要的。该怎么办?一样;DrawingVisual
仅被视为简化示例,但您需要使用其他内容。
请查看一个Visual
类: http://msdn.microsoft.com/en-us/library/system.windows.media.visual.aspx [ ^ ]。
你可以看到这个类是System.Windows.UIElement
的基类,因此,你感兴趣的任何东西。这解决了你的问题。
-SA
Lets start from the very end: transparency won''t be a problem, because PNG bitmaps support transparency: http://en.wikipedia.org/wiki/Portable_Network_Graphics[^].
For rendering of something like a control on a bitmap (you actually can render anyVisual
and hence any control; please see below), you need to use the classesSystem.Windows.Media.DrawingVisual
andSystem.Windows.Media.Imaging.RenderTargetBitmap
:
http://msdn.microsoft.com/en-us/library/system.windows.media.drawingvisual.aspx[^],
http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.rendertargetbitmap.aspx[^].
If you look at the MSDN help page for the classDrawingVisual
, referenced above, you will see a code sample for creating a bitmap from aSystem.Windows.Media.Visual
, but for theVisual
the classSystem.Windows.Media.DrawingVisual
is used, which you don''t need. What to do? Same thing;DrawingVisual
is considered only to make the example short, but you will need to use something else.
Please look a theVisual
class: http://msdn.microsoft.com/en-us/library/system.windows.media.visual.aspx[^].
You can see that this class is a base class forSystem.Windows.UIElement
, and, hence, anything you are interested in. That solves your problem.
—SA
这篇关于WPF:如何将任何东西保存为图像vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文