Use WPF in combination with Hardware Rendering instead of RenderTargetBitmap
The WPF application I have build has a Viewport3D containg all kinds of UIElement3D objects. Now I would like to save a high resolution snapshot of a certain view to a file. I have tried RenderTargetBitmap in the past, but I do not like this approach because of the following do开发者_StackOverflow中文版wnsides:
- Memory leakage (at least with .NET 3.5 SP1). It should be solved however with 4.0, but I have not tested that yet.
- Software rendering does not give the same results as hardware rendering when using anti-aliasing and pixel shaders.
- RenderTargetBitmap needs a lot of time (like 10 seconds) to form an image, instead of fraction of a second needed for display on screen.
So I wonder whether it would be possible to use a VisualBrush, containing a snapshot copy, in a new control/window (preferably offscreen) and then grab the contents trough the front- or backbuffer using DirectX or GDI techniques. I could imagine that resolution beyond capabilities of graphics card might be a problem, but that could be solved by grabbing multiple sub images and stitch them together aftwerwards. So anyone with some ideas on this topic?
Please keep in mind that I have read about DirectX, XNA, SlimDX, GDI+, BitBlt and so on, but that's about all the experience I have on these matters. Target platform is Windows XP+. If a solution is possible but not on XP, I would like to know also.
Best regards,
Jan van de Pol
This is a tricky issue since WPF keeps so much of its internal workings to itself, but a friend of mine, Jeremiah Morrill, has discovered a way to tap into the underlying DirectX surface that WPF uses when rendering a window. I've used it for a project that sounds like it had a very similar requirement to yours, and it worked beautifully (and FAR faster than using any of the "proscribed" methods WPF gives you).
You may have to familiarize yourself with a bit more DirectX (not too much, I promise!) but you can read about it and download the working source code from his blog here:
http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/438/How-to-get-access-to-WPF-s-internal-Direct3D-guts.aspx
精彩评论