Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement