Version: 2017.3 (switch to 2017.4)
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

ImageConversion.EncodeToEXR

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static method EncodeToEXR(tex: Texture2D, flags: Texture2D.EXRFlags = Texture2D.EXRFlags.None): byte[];
public static byte[] EncodeToEXR(Texture2D tex, Texture2D.EXRFlags flags = Texture2D.EXRFlags.None);

Parameters

tex The texture to convert.
flags Flags used to control compression and the output format.

Description

Encodes this texture into the EXR format.

This function returns a byte array which is the EXR file data. Write this data to disk to get the data in the EXR file format.

It is best to use this function for HDR texture formats (either 16-bit or 32-bit floats). The default output format is 16-bit float EXR and the texture passed must have the Is Readable flat set in the import settings.

The encoded EXR data will always contain an alpha channel.

See Also: EXRFlags, EncodeToJPG, EncodeToPNG.

no example available in JavaScript
// Saves HDR RenderTexture as an EXR file.
using UnityEngine;
using System.Collections;
using System.IO;

public class SaveRenderTextureToEXR : MonoBehaviour { RenderTexture m_InputTexture;

void SaveRenderTexture() { if (m_InputTexture != null) { int width = m_InputTexture.width; int height = m_InputTexture.height;

Texture2D tex = new Texture2D(width, height, TextureFormat.RGBAFloat, false);

// Read screen contents into the texture Graphics.SetRenderTarget(m_InputTexture); tex.ReadPixels(new Rect(0, 0, width, height), 0, 0); tex.Apply();

// Encode texture into the EXR byte[] bytes = tex.EncodeToEXR(Texture2D.EXRFlags.CompressZIP); File.WriteAllBytes(Application.dataPath + "/../SavedRenderTexture.exr", bytes);

Object.DestroyImmediate(tex); } } }

Did you find this page useful? Please give it a rating: