Screenshot

A picture is worth a thousand words and about 500 lines of code ... this lets you do it in 1

Like what your seeing?

Support us as a GitHub Sponsor and get instant access to all our assets, exclusive tools and assets, escalated support and issue tracking and our gratitude. These articles are made possible by our GitHub Sponsors ... become a sponsor today!

Introduction

public static class API.Screenshot

This interface enables you to capture full screen or parts of a screen to texture, to file and to optionally scale the data to suit your needs.

What can it do?

  • Capture full screen to texture

  • Capture a rect of the screen to texture

  • Scale a texture (point or bilinear)

  • save a texture or the screen or part of the screen to disk

How To

All processes are asynchronious and require you to pass in a MoboBehaviour so that the interface can detect the end of frame insuring a proper capture of the redering.

Once complete the callback will be invoked providing you with the completed texture and a boolean indicating IO Failure if any for example

API.Screenshot.Capture(this, (texture, failure) => 
{
    if(!failure)
        Debug.Log("texture contains the screen shot!");
});

Capture the full screen

API.Screenshot.Capture(component, callback);

Capture part of the screen

From repreesnts the lower left and To represents the upper rigth of the corners of the screen rect to be taken, these are in pixel space e.g. (0,0) & (256,256) would capture a 256x256 area at the botton left corner of the screen.

API.Screenshot.Capture(componenet, from, to, callback);

Save image to file

You can capture and save in a single line call to any of Unity's supported encoding types. The save image operation can also be used on Texture2D so you can save any texture you have available.