Skip to content

Commit

Permalink
Merge pull request #171 from Doprez/screenshot-extension
Browse files Browse the repository at this point in the history
feat: Simple screenshot extension
  • Loading branch information
VaclavElias authored Oct 28, 2024
2 parents 6f29208 + c931af1 commit 2ee13c0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/Stride.CommunityToolkit/Engine/GameExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Stride.Engine;
using Stride.Engine.Processors;
using Stride.Games;
using Stride.Graphics;
using Stride.Physics;
using Stride.Rendering;
using Stride.Rendering.Colors;
Expand Down Expand Up @@ -616,6 +617,21 @@ public static Entity Create3DPrimitive(this IGame game, PrimitiveModelType type,
return entity;
}

/// <summary>
/// Saves a screenshot of the current frame to the specified file path.
/// </summary>
/// <param name="game"></param>
/// <param name="fileName">creates a file with this name</param>
/// <param name="fileType"></param>
public static void TakeScreenShot(this IGame game, string fileName, ImageFileType fileType = ImageFileType.Png)
{
using (var stream = File.Create(fileName))
{
var commandList = game.GraphicsContext.CommandList;
commandList.RenderTarget.Save(commandList, stream, fileType);
}
}

/// <summary>
/// Adds a scene renderer to the game's <see cref="GraphicsCompositor"/>.
/// </summary>
Expand Down

0 comments on commit 2ee13c0

Please sign in to comment.