mirror of
https://github.com/Facepunch/Facepunch.Steamworks.git
synced 2025-04-12 04:20:04 +03:00
Added AddScreenshotToLibrary(filename, thumbnailFilename, width, height); and AddScreenshotToLibrary(filename, width, height); We use Application.TakeScreenshot(path, superSize) in some of our in-game tools (like the camera) to allow for higher-res screenshots, and this feels like a much faster way of doing it then loading the PNG back into a texture2D, converting it into a correct format, and using Write.
81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
|
|
namespace Facepunch.Steamworks
|
|
{
|
|
public partial class Client : IDisposable
|
|
{
|
|
Screenshots _screenshots;
|
|
|
|
public Screenshots Screenshots
|
|
{
|
|
get
|
|
{
|
|
if ( _screenshots == null )
|
|
_screenshots = new Screenshots( this );
|
|
|
|
return _screenshots;
|
|
}
|
|
}
|
|
}
|
|
|
|
public class Screenshots
|
|
{
|
|
internal Client client;
|
|
|
|
internal Screenshots( Client c )
|
|
{
|
|
client = c;
|
|
}
|
|
|
|
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 );
|
|
}
|
|
}
|
|
|
|
public unsafe void AddScreenshotToLibrary( string filename, string thumbnailFilename, int width, int height)
|
|
{
|
|
client.native.screenshots.AddScreenshotToLibrary(filename, thumbnailFilename, width, height);
|
|
}
|
|
|
|
public unsafe void AddScreenshotToLibrary( string filename, int width, int height)
|
|
{
|
|
client.native.screenshots.AddScreenshotToLibrary(filename, null, width, height);
|
|
}
|
|
}
|
|
}
|