Screenshot: Unterschied zwischen den Versionen
Aus Das Sopra Wiki
K verlinkung vervollständigt, finalisiert |
Keine Bearbeitungszusammenfassung |
||
| (3 dazwischenliegende Versionen von 2 Benutzern werden nicht angezeigt) | |||
| Zeile 22: | Zeile 22: | ||
== Erstellen von [[Screenshot]]s aus XNA == | == Erstellen von [[Screenshot]]s aus XNA == | ||
<source lang="csharp"> | <source lang="csharp"> | ||
private void Screenshot() | private void Screenshot() | ||
{ | { | ||
//create a render target to render the screenshot into | |||
RenderTarget2D screenshotTarget = new RenderTarget2D(GraphicsDevice, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8); | |||
//set the render target on the graphics device | |||
GraphicsDevice.SetRenderTarget(screenshotTarget); | |||
//call the draw code of the game to draw it into the render target | |||
this.Draw(); | |||
//create a filestream to save the rendered screenshot onto disk | |||
FileStream fs = new FileStream("screen.png", FileMode.OpenOrCreate); | |||
//reset the render target of the graphics device for normal drawing | |||
GraphicsDevice.SetRenderTarget(null); | |||
//save the screenshot to disk and close the file stream | |||
screenshotTarget.SaveAsPng(fs, screenshotTarget.Width, screenshotTarget.Height); | |||
fs.Flush(); | |||
fs.Close(); | |||
} | } | ||
</source> | </source> | ||
[[Kategorie:Tools]] | [[Kategorie:Tools]] | ||
[[Kategorie:Tutorials]] | [[Kategorie:Tutorials]] | ||
[[Kategorie:Begriffe]] [[Kategorie:Code-Beispiele]] | [[Kategorie:Begriffe]] [[Kategorie:Code-Beispiele]] | ||
[[Kategorie:MS02]] | |||
[[Kategorie:MS03]] | |||
[[Kategorie:MS04]] | |||
[[Kategorie:MS05]] | |||
