Skip to content

Instantly share code, notes, and snippets.

@openroomxyz
Created April 6, 2020 11:26
Show Gist options
  • Save openroomxyz/bb22a79fcae656e257d6153b867ad437 to your computer and use it in GitHub Desktop.
Save openroomxyz/bb22a79fcae656e257d6153b867ad437 to your computer and use it in GitHub Desktop.
Unity : How to load Texture2d from file (PNG) on disk?
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