diff --git a/Facepunch.Steamworks/Client/Screenshots.cs b/Facepunch.Steamworks/Client/Screenshots.cs index fa75b35..a0a9f2b 100644 --- a/Facepunch.Steamworks/Client/Screenshots.cs +++ b/Facepunch.Steamworks/Client/Screenshots.cs @@ -35,5 +35,36 @@ public void Trigger() client.native.screenshots.TriggerScreenshot(); } + public unsafe void Write( byte[] rgbData, int width, int height ) + { + if ( rgbData == null ) + { + throw new ArgumentNullException( nameof(rgbData) ); + } + + if ( width < 1 ) + { + throw new ArgumentOutOfRangeException( nameof(width), width, + $"Expected {nameof(width)} to be at least 1." ); + } + + if ( height < 1 ) + { + throw new ArgumentOutOfRangeException( nameof(height), height, + $"Expected {nameof(height)} to be at least 1." ); + } + + var size = width * height * 3; + if ( rgbData.Length < size ) + { + throw new ArgumentException( nameof(rgbData), + $"Expected {nameof(rgbData)} to contain at least {size} elements (actual size: {rgbData.Length})." ); + } + + fixed ( byte* ptr = rgbData ) + { + client.native.screenshots.WriteScreenshot( (IntPtr) ptr, (uint) rgbData.Length, width, height ); + } + } } }