Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.IO;
  4. using UnityEngine.UI;
  5.  
  6. public class LoadTexture : MonoBehaviour {
  7.  
  8. // Use this for initialization
  9. void Start () {
  10. Image img = GetComponent<Image> ();
  11. Texture2D texture = LoadIMG("C:/Users/Jack/Desktop/test.jpg");
  12. img.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
  13. }
  14.  
  15. // Update is called once per frame
  16. void Update () {
  17.  
  18. }
  19.  
  20. public static Texture2D LoadIMG(string filePath) {
  21.  
  22. Texture2D tex = null;
  23. byte[] fileData;
  24.  
  25. if (File.Exists(filePath)) {
  26. fileData = File.ReadAllBytes(filePath);
  27. tex = new Texture2D(2, 2);
  28. tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
  29. }
  30. return tex;
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement