ES3.LoadImage
Load Image
Description
Loads a JPG or PNG image file as a Texture2D.
A FileNotFoundException will be thrown if the file does not exist. In this case, you can use ES3.FileExists to check if the data exists before loading.
An ArgumentException will be thrown if the file extension is not jpg, jpeg, or png.
Parameters
imagePath | The relative or absolute path of the JPG or PNG image file we want to load. |
settings |
[Optional] The settings we want to use to override the default settings. |
Returns
The loaded Texture2D.
Examples
C#
1 2 3 4 |
// Load a Texture2D from a PNG file. var texture = ES3.LoadImage("myImage.png"); // Apply the Texture2D to the material on this object. GetComponent<Renderer>.material.mainTexture = texture; |
JS
1 2 3 4 |
// Load a Texture2D from a PNG file. var texture = ES3.LoadImage("myImage.png"); // Apply the Texture2D to the material on this object. GetComponent.<Renderer>.material.mainTexture = texture; |
Load Image From Bytes
Description
Loads the bytes of a JPG or PNG image file as a Texture2D.
Parameters
bytes | The bytes representing our JPG or PNG. |
Returns
The loaded Texture2D.
Examples
C#
1 2 3 4 |
// Get the bytes of a PNG file from an external cloud service. byte[] bytes = CloudService.GetFileBytes("file.png"); // Turn these bytes into a Texture2D. var texture = ES3.LoadImage(bytes); |
JS
1 2 3 4 |
// Get the bytes of a PNG file from an external cloud service. byte[] bytes = CloudService.GetFileBytes("file.png"); // Turn these bytes into a Texture2D. var texture = ES3.LoadImage(bytes); |