I would basically like to screen开发者_JAVA技巧 capture a GPU result into a bitmap file using .NET. I would probably use XNA and my workflow would be something like:
- Call an effect with custom input data
- Have the effect run a per-pixel process
- Get the result from the effect (???)
- Save result as bitmap
Thanks...
Edit
Summary from Liortal's answer:
To use a render target, create a RenderTarget2D object with the width, height, and other options you prefer. Then call GraphicsDevice.SetRenderTarget to make your render target the current render target. From this point on, any Draw calls you make will draw into your render target. When you are finished with the render target, call GraphicsDevice.SetRenderTarget to a new render target (or null for the back buffer). Then at any time you can call RenderTarget2D.GetTexture to get the contents of the render target for further processing.
Read more about Render Targets and how to use them here: http://msdn.microsoft.com/en-us/library/bb976073.aspx
Note that the link refers up to XNA 3.1, here's a post by the awesome Shawn Hargreaves about changes made in this area in XNA 4: http://blogs.msdn.com/b/shawnhar/archive/2010/03/26/rendertarget-changes-in-xna-game-studio-4-0.aspx
RenderTarget
's are what you are after here. Set the RenderTarget
(graphicsDevice.SetRenderTarget(myRenderTarget);
), draw your scene and then use either SaveAsJpeg
or SaveAsPng
methods to save the output.
Here is the XNA 4 version of the RenderTarget documentation.
However, people have mentioned about memory leaks, so I would use this alternative:
BmpWriter
This link has the source code that you require (as I mentioned above).
精彩评论