Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.IO;
- using UnityEngine.UI;
- public class LoadTexture : MonoBehaviour {
- // Use this for initialization
- void Start () {
- Image img = GetComponent<Image> ();
- Texture2D texture = LoadIMG("C:/Users/Jack/Desktop/test.jpg");
- img.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
- }
- // Update is called once per frame
- void Update () {
- }
- public static Texture2D LoadIMG(string filePath) {
- Texture2D tex = null;
- byte[] fileData;
- if (File.Exists(filePath)) {
- fileData = File.ReadAllBytes(filePath);
- tex = new Texture2D(2, 2);
- tex.LoadImage(fileData); //..this will auto-resize the texture dimensions.
- }
- return tex;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement