Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make screenshot using C# & XNA?

Tags:

c#

xna

xna-4.0


How to make screenshot and save it to HDD using C# & XNA, while running game in fullscreen mode?

like image 383
Neomex Avatar asked Apr 03 '11 13:04

Neomex


1 Answers

The API was changed in XNA 4.0.

If you are running on the HiDef profile (Xbox 360 and newer Windows machines), you can use GraphicsDevice.GetBackBufferData.

To make saving that data easy, you could use put the output from that into a Texture2D.SetData and then use SaveAsPng or SaveAsJpeg (this is slightly slower than it needs to be, because it also sends the data back to the GPU - but it is just so easy).

If you are using the Reach profile, then you have to render your scene to a RenderTarget2D. My answer here should give you a good starting point.

like image 123
Andrew Russell Avatar answered Sep 29 '22 21:09

Andrew Russell