Stride Forums Archive

Can I save RenderTexture as png file?

2 posts, 2259 views, 2020-05-24 to 2020-05-26

bethleem 2020-05-24 #1

I need to take ingame captures of the screen, so I render the camera output to a RenderTexture. Now, I need that texture to be saved as a png (or bmp, anything but jpg). Looking into stride API I was unable to find a proper function. So, is there a way yo save a rendertexture to a png file?

The external screen capture software is NOT a solution, it may be done inside the game.

Thx in advance.

xen2 (Virgile) 2020-05-26 #2

Here’s how you could dump a texture to a file:

using (var image = texture.GetDataAsImage(GraphicsContext.CommandList))
using (var resultFileStream = File.OpenWrite(filename))
    image.Save(resultFileStream, ImageFileType.Png);