- Home /
 
Answer by UnityCoach · Mar 31, 2017 at 12:05 AM
This really depends on the platform you target.
Anyway, you'll have to go with a RawImage, as it uses a Texture2D, which can be loaded at runtime.
Texture2D can be loaded from StreamingAssets Path for example, or from the user documents folder.
If you want the user to locate a file on their computer, consider buying an extension from the AssetStore, there's one that allows to have a file open dialog at runtime.
I'd want this to occur during run time not beforehand. Thanks!
Answer by alexmeister92 · Apr 02, 2017 at 10:03 AM
Users could specify the url/path then the system loads the image like the following example
 using System.Collections;
 using UnityEngine;
 using UnityEngine.UI;
 
 public class NewBehaviourScript : MonoBehaviour
 {
     [SerializeField]
     private Image background;
 
     [SerializeField]
     private string url;
     // local: url = "file:///D:/Images/example.jpg";
     // internet: url = "http://i.imgur.com/UVk2aZZ.png";
 
     void Start ()
     {
         StartCoroutine(downloadImage(url));
     }
 
     private IEnumerator downloadImage(string urlImage)
     {
         WWW wwwRequest = new WWW(urlImage);
         yield return wwwRequest;
 
         if (wwwRequest.error != null)
         {
             Debug.Log("<color=red>Error: " + wwwRequest.error + "</color>");
             yield break;
         }
 
         Texture2D image = wwwRequest.texture;
         background.sprite = Sprite.Create(image, new Rect(0f, 0f, image.width, image.height), Vector2.zero);
     }
 }
 
              In Unity 5.6 you need to load the image like the following:
 Texture2D image = new Texture2D(1, 1, TextureFormat.DXT5, false);
 wwwRequest.LoadImageIntoTexture(image);
 
                  
                 Your answer
 
             Follow this Question
Related Questions
[Solved]Why my Unity Button's Positions are different. 1 Answer
Image that is instantiated through GameObject.Instatiate does not render 1 Answer
UI fade with CanvasGroup vs of Image.color.alpha or Text.color.alpha performance 1 Answer
Is It Possible to Render the same Data to 2 Different UI Text Objects? 1 Answer
Ui scaling 1 Answer