Skip to content

Instantly share code, notes, and snippets.

@bobbyg603
Created April 25, 2021 21:56
Show Gist options
  • Save bobbyg603/5aff7992f94046928780e00b2b491d6f to your computer and use it in GitHub Desktop.
Save bobbyg603/5aff7992f94046928780e00b2b491d6f to your computer and use it in GitHub Desktop.
In memory screenshot in Unity
private byte[] CaptureInMemoryPngScreenshot()
{
// TODO BG the example calls Destory on texture, do we need to do that?
var texture = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
texture.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
texture.Apply();
return texture.EncodeToPNG();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment