Created
April 6, 2020 11:26
-
-
Save openroomxyz/bb22a79fcae656e257d6153b867ad437 to your computer and use it in GitHub Desktop.
Unity : How to load Texture2d from file (PNG) on disk?
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
private static Texture2D LoadPNG(string filePath) | |
{ | |
Texture2D tex = null; | |
byte[] fileData; | |
if (System.IO.File.Exists(filePath)) | |
{ | |
fileData = System.IO.File.ReadAllBytes(filePath); | |
tex = new Texture2D(2, 2); | |
tex.LoadImage(fileData); //..this will auto-resize the texture dimensions. | |
} | |
return tex; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment