Saving and Loading Images
You can use Easy Save to to load a JPEG or PNG image as a Texture2D. You can also save a Texture2D as a PNG.
Loading an Image as a Texture2D
You can load a JPEG or PNG file as a Texture2D using ES2.LoadImage.
For example, to load a JPG from a user’s hard drive into a GameObject’s material, you could use the following code:
1 |
renderer.material.mainTexture = ES2.LoadImage("C:/Users/User/myImage.jpg"); |
Saving a Texture2D as a PNG
To save a Texture2D as a PNG, you use the ES2.SaveImage method.
For example, to save the Texture2D assigned to a GameObject’s material, you could use the following code:
1 |
ES2.SaveImage(renderer.material.mainTexture, "C:/Users/User/MyImage.png"); |