Re: [Unity] get Texture2D from textureSource?
It's works fine.
I save the captured image to a file to check it and always works fine without exceptions.
I save the captured image to a file to check it and always works fine without exceptions.
Code: Select all
IEnumerator RenderAtEndOfFrame()
{
yield return new WaitForEndOfFrame();
_uiRenderer.PostRender();
Texture2D tex= new Texture2D(100, 100, TextureFormat.ARGB32, false);
// Read screen contents into the texture
tex.ReadPixels(new UnityEngine.Rect(100, 100, 100, 100), 0, 0);
tex.Apply();
//Convert the texture to a PNG
byte[] bytes = tex.EncodeToPNG();
// Write the PNG to check if capture works fine
System.IO.File.WriteAllBytes(Application.persistentDataPath + "test.png", bytes);
//Assign null to the variables to avoid memory exception
tex= null;
bytes = null;
}
Re: [Unity] get Texture2D from textureSource?
That is the explanation then. In future revisions we could add a delegate to avoid having you to patch our code.
Who is online
Users browsing this forum: Google [Bot] and 6 guests