ES3.LoadImage

public static Texture2D LoadImage(string imagePath, ES3Settings settings)

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 jpgjpeg, or png.

Parameters

[table th=”0″]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.”[/table]

Returns

The loaded Texture2D.

Examples

C#

// 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

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

public static Texture2D LoadImage(byte[] bytes)

Description

Loads the bytes of a JPG or PNG image file as a Texture2D.

Parameters

[table th=”0″]bytes,”The bytes representing our JPG or PNG.”[/table]

Returns

The loaded Texture2D.

Examples

C#

// 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

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