从 WPF 应用程序窗口获取位图? [英] Get a Bitmap from a WPF application window?
问题描述
Winforms System.Windows.Forms.Control 类有一个实例方法DrawToBitmap",我认为它在各种情况下都非常有用.我想知道是否有从 WPF 应用程序获取 System.Drawing.Bitmap 的等效方法?
The Winforms System.Windows.Forms.Control class has an instance method "DrawToBitmap" which I think is very useful in a variety of circumstances. I'm wondering if there's an equivalent way of getting a System.Drawing.Bitmap from a WPF application?
我意识到我可以做一些 P/Invoke 的东西来获取应用程序窗口,但是我不喜欢这样,因为它不能很好地适应 64 位转换,并且不允许我只渲染子控件,就像 DrawToBitmap 一样.
I realize I could do some P/Invoke stuff to just get the application window, however I don't like this because it doesn't accomodate the 64bit transition very well, and doesn't let me render sub-controls only, as DrawToBitmap does.
谢谢,理查德
推荐答案
Use RenderTargetBitmap as on MSDN
Use RenderTargetBitmap as on MSDN
RenderTargetBitmap bitmap = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
bitmap.Render(this.YourVisualControlNameGoesHere);
这篇关于从 WPF 应用程序窗口获取位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!