ScriptReference/Texture-isReadable #576
Replies: 1 comment
-
|
You can use this code to get a readable version of a non-readable texture. Note that you should Destroy manually-created assets when you are done with them. if (!texture2D.isReadable)
{
RenderTexture tmp = RenderTexture.GetTemporary(texture2D.width, texture2D.height, 0, texture2D.graphicsFormat, 1);
Graphics.Blit(texture2D, tmp);
RenderTexture previous = RenderTexture.active;
RenderTexture.active = tmp;
Texture2D newTex = new Texture2D(texture2D.width, texture2D.height) { name = texture2D.name };
newTex.ReadPixels(new Rect(0, 0, tmp.width, tmp.height), 0, 0);
newTex.Apply();
RenderTexture.active = previous;
RenderTexture.ReleaseTemporary(tmp);
texture2D = newTex;
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
ScriptReference/Texture-isReadable
https://docs.unity3d.com/ScriptReference/Texture-isReadable.html
Beta Was this translation helpful? Give feedback.
All reactions