How can I take a screenshot, without saving it as a PNG, but to a tex2d?
I have a problem. I am using the unity function "capturescreenshot", and I am saving the image to my game's save folder. However, the images take up too much space, so I want to take the screenshot as a tex2d, reduce the resolution, and convert it to a byte array, so it can be saved in the binary save file. I have so far been unable to take the screenshot as a tex2d, and there does not seem to be a function to convert it to a byte array. I also do not know how to convert a byte array back to a tex2d. I have the entire script already programmed, but I am now left with these two problems. It would be appreciated if anyone could help me solve this problem.
Answer by JedBeryll · Nov 03, 2016 at 06:28 AM
You can create a new Texture2D and call ReadPixels on it. Then you can encode to png or jpg or you can resize the texture and there's the GetPixels32 which returns the color values as bytes. Look around in Texture2D functions here. Also the camera has a targetTexture that may be useful for you.
@JedBeryll , how can I exclude the ui during the ReadPixels function? Is it possible to do without creating another camera?
I would just find and disable the ui for the frame that takes the picture.
@JedBeryll , Is that possible to do without the player seeing the ui disappear for a frame, or will I need to use another camera?