Skip to content

Instantly share code, notes, and snippets.

@zxzsaga
Last active March 29, 2019 05:11
Show Gist options
  • Select an option

  • Save zxzsaga/ccb0a1907a2e2880754c66064145d8b7 to your computer and use it in GitHub Desktop.

Select an option

Save zxzsaga/ccb0a1907a2e2880754c66064145d8b7 to your computer and use it in GitHub Desktop.
Load png or jpg file in Unity.
/// <summary>
/// Load png or jpg file.
/// </summary>
public static Texture2D LoadImage(string filePath) {
if (!File.Exists(filePath)) {
return null;
}
Texture2D tex = new Texture2D(1, 1);
byte[] fileData = File.ReadAllBytes(filePath);
tex.LoadImage(fileData);
return tex;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment