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();

         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);

       //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
Site Admin
Posts: 3914
Joined: 20 Jan 2012, 17:18

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: Ahrefs [Bot], Google [Bot], hcpizzi and 1 guest