- Home /
(iOs) Saving screenshot as a file, and retrieving it again as a Texture
On iOs, I need to save the current screen as a file, where I can load it afterwards as a texture to display it on GUI ( I usually use Resources.load, but I am guessing I'll have to do it in another way ).
I tried Application.CaptureScreenshot with and without Application.persistentDataPath.
I also tried System.IO.File.WriteAllBytes with ReadPixels on a Texture2d instance.
I think the file is beeing saved, though I can't figure out a way to get it back, specially as a Texture2d.
please help.
PS: I'm using C# but any help here would be much appreciated
Answer by hathol · Aug 07, 2012 at 03:07 AM
If you have your image as a Texture2D, you can use yourTexture.EncodeToPNG to get a byte[] that you can write to disk with File.WriteAllBytes. I usually use Application.persistentDataPath+"/Images/yourFilename.png".
For loading, just use File.ReadAllBytes with the same path and Texture2D.LoadImage to put the byte[] back into a new Texture2D (just make sure you have the same size again).
Answer by FatWednesday · Aug 13, 2012 at 02:16 PM
Is there any particular reason you need to even save the file before using it?
Im just trying to see why you would need to save the file externaly instead of just using Textude2D.ReadPixels() to grab the framebuffer directly as a Texture2D and then use that. Cutting out the cost of saving and re-loading from a file.
Your answer
