fedegen
Topic Author
Posts: 6
Joined: 30 Sep 2015, 22:25

Re: [Unity] get Texture2D from textureSource?

10 Dec 2015, 14:59

It's works fine.
I save the captured image to a file to check it and always works fine without exceptions.
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;
}
 
User avatar
jsantos
Site Admin
Posts: 4266
Joined: 20 Jan 2012, 17:18
Contact:

Re: [Unity] get Texture2D from textureSource?

17 Dec 2015, 15:10

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