osu.Framework/Platform/GameHost.cs
/// <summary>
/// Takes a screenshot of the game. The returned <see cref="Image{TPixel}"/> must be disposed by the caller when applicable.
/// </summary>
/// <returns>The screenshot as an <see cref="Image{TPixel}"/>.</returns>
Takes a screenshot of the game. The returned  must be disposed by the caller when applicable.
Takes a screenshot of the game . The returned must be disposed by the caller when applicable .
public async Task<Image<Rgba32>> TakeScreenshotAsync()
        {
            if (Window == null) throw new NullReferenceException(nameof(Window));
            var image = new Image<Rgba32>(Window.ClientSize.Width, Window.ClientSize.Height);
            bool complete = false;
            DrawThread.Scheduler.Add(() =>
            {
                if (GraphicsContext.CurrentContext == null)
                    throw new GraphicsContextMissingException();
                GL.ReadPixels(0, 0, image.Width, image.Height, PixelFormat.Rgba, PixelType.UnsignedByte, ref MemoryMarshal.GetReference(image.GetPixelSpan()));
                complete = true;
            });
            await Task.Run(() =>
            {
                while (!complete)
                    Thread.Sleep(50);
            });
            image.Mutate(c => c.Flip(FlipMode.Vertical));
            return image;
        }
public async Task < Image < Rgba32 > > TakeScreenshotAsync ( ) { if ( Window == null ) throw new NullReferenceException ( nameof ( Window ) ) ; var image = new Image < Rgba32 > ( Window . ClientSize . Width , Window . ClientSize . Height ) ; bool complete = false ; DrawThread . Scheduler . Add ( ( ) => { if ( GraphicsContext . CurrentContext == null ) throw new GraphicsContextMissingException ( ) ; GL . ReadPixels ( 0 , 0 , image . Width , image . Height , PixelFormat . Rgba , PixelType . UnsignedByte , ref MemoryMarshal . GetReference ( image . GetPixelSpan ( ) ) ) ; complete = true ; } ) ; await Task . Run ( ( ) => { while ( ! complete ) Thread . Sleep ( 50 ) ; } ) ; image . Mutate ( c => c . Flip ( FlipMode . Vertical ) ) ; return image ; }
Takes a screenshot of the game.
Takes a screenshot of the game .
// this is required as attempting to use a TaskCompletionSource blocks the thread calling SetResult on some configurations.
The screenshot as an .
The screenshot as an .