Last active
March 29, 2019 05:11
-
-
Save zxzsaga/ccb0a1907a2e2880754c66064145d8b7 to your computer and use it in GitHub Desktop.
Load png or jpg file in Unity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /// <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