Class ScreenCapture
- Namespace
- Forma
- Assembly
- Forma.dll
Saves what was drawn to a PNG.
public static class ScreenCapture
- Inheritance
-
ScreenCapture
- Inherited Members
Remarks
Here rather than in each application because every one of them ends up writing it: a
sample's --screenshot flag, a test harness capturing a failure, a tool exporting a
preview. They were all the same ten lines, and each copy re-learned the timing rule below
the hard way.
Methods
SaveBackBuffer(GraphicsDevice, string)
Writes the current back buffer to path as a PNG.
public static void SaveBackBuffer(GraphicsDevice device, string path)
Parameters
deviceGraphicsDevicepathstring
Remarks
Call this at the end of a draw, not from outside the loop. A back buffer that has not been presented reads back cleared, so a capture taken from a test between frames produces a solid black image — one that looks like a real screenshot of a broken UI rather than like a mistake in the capture.
A headless backend discards every draw call, so there is nothing to capture there either. Callers that can be run both ways should say which they are rather than writing a black rectangle.