Class ImageCapture
Utility class for capturing images from the back buffer or render textures.
Inherited Members
Namespace: UnityEngine.TestTools.Graphics
Assembly: UnityEngine.TestTools.Graphics.dll
Syntax
public static class ImageCapture
Methods
BilinearResize(TextureFormat, (int ResolutionX, int ResolutionY), Texture2D)
Resizes the texture2D to the desired dimension, with the specified format, using a bilinear algorithm.
Declaration
public static Texture2D BilinearResize(TextureFormat targetFormat, (int ResolutionX, int ResolutionY) targetSize, Texture2D textureToResize)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureFormat | targetFormat | Target format |
| (int ResolutionX, int ResolutionY) | targetSize | Target size in in a tuple format |
| Texture2D | textureToResize | The texture to resize |
Returns
| Type | Description |
|---|---|
| Texture2D | The resized texture |
CaptureBackBuffer(TextureFormat, Rect)
Captures frames from the backbuffer into the specified Texture2D format, using the capture rectangle within the current screen resolution.
Declaration
public static Texture2D CaptureBackBuffer(TextureFormat textureOutputFormat, Rect captureRect)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureFormat | textureOutputFormat | Texture output format |
| Rect | captureRect | The rectangle that corresponds to the location and dimension of the capture |
Returns
| Type | Description |
|---|---|
| Texture2D | A texture2D of the specified texture format and rectangle size |
CaptureBackbuffer(TextureFormat)
Captures frames from the backbuffer into the specified Texture2D format. The resolution of the screen will be used for the texture's dimensions.
Declaration
public static IEnumerable<Texture2D> CaptureBackbuffer(TextureFormat textureOutputFormat)
Parameters
| Type | Name | Description |
|---|---|---|
| TextureFormat | textureOutputFormat | Texture output format |
Returns
| Type | Description |
|---|---|
| IEnumerable<Texture2D> | An enumerable collection of Texture2Ds |
Remarks
Supported format are RGBA32, ARGB32, RGB24, ARGBFloat, RGBAFloat, RGBAHalf, R16, RG16, R8. Capture might fail on some platforms if using other texture formats.
CaptureFromCamera(Camera, TextureFormat, CameraCaptureSettings, int)
Captures frames from the specified camera into a Texture2D of the specified format.
Declaration
public static IEnumerable<Texture2D> CaptureFromCamera(Camera captureCam, TextureFormat textureOutputFormat, CameraCaptureSettings settings, int numberOfRenderedFramesBeforeCapture = 0)
Parameters
| Type | Name | Description |
|---|---|---|
| Camera | captureCam | Camera from which the texture will be captured |
| TextureFormat | textureOutputFormat | Texture output format |
| CameraCaptureSettings | settings | Camera capture settings |
| int | numberOfRenderedFramesBeforeCapture | Number of frames to render before capturing. When running within the editor, an extra frame needs to be rendered in order to make sure shader variants are ready. |
Returns
| Type | Description |
|---|---|
| IEnumerable<Texture2D> | An enumerable collection of Texture2Ds |
SaveAsActual(Texture2D, string, bool, bool)
Saves a Texture2D to the ActualImages folder in PNG or EXR format.
Declaration
public static void SaveAsActual(Texture2D texture, string nameWithoutExtension, bool alsoSaveToDevicePersistentStorage = false, bool useEXR = false)
Parameters
| Type | Name | Description |
|---|---|---|
| Texture2D | texture | Texture to be saved |
| string | nameWithoutExtension | The name of the file. The extension .png is added by default. |
| bool | alsoSaveToDevicePersistentStorage | Additionally to the ActualImages folder, also saves to the device persistent storage so that it's available after reboot. |
| bool | useEXR | Save in EXR format for HDR format. If the image is not using an HDR texture format, a warning will be logged. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Texture needs to be not null |
| ArgumentException | An image needs to be provided |