daily pastebin goal
26%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void LoadPNG(string filePath, Button btn)
  2.     {
  3.  
  4.         Texture2D tex = null;
  5.         byte[] fileData;
  6.  
  7.         if (File.Exists(filePath))
  8.         {
  9.             fileData = File.ReadAllBytes(filePath);
  10.             tex = new Texture2D(2, 2);
  11.             tex.Apply();
  12.             Sprite img = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
  13.             btn.image.sprite = img;
  14.  
  15.             //tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
  16.         }
  17.  
  18.         else
  19.             Debug.LogError("Could't load thumbnail image from streaming assets.");
  20.        
  21.  
  22.  
  23.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top