Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Requiem99 · Mar 27, 2015 at 08:36 AM · androidunity 4.6www.texture

Problem dipsplaying an image from url to UI.Image component

Hi! What I need to do is download an image from a url and display it in a UI.Image component (so as sprite). I managed to do this with the script below, but only seems to work in unity, while not working on my android tablet (application crash).

     public void Start () {
         StartCoroutine(RealLoadImage());
     }
         
     private IEnumerator RealLoadImage () {
         string url = "http://www.MY_URL_IMAGE...";
         WWW imageURLWWW = new WWW(url);  
         
         yield return imageURLWWW;        
         
         if(imageURLWWW.texture != null)
         {
             Sprite sprite = new Sprite();     
             sprite = Sprite.Create(imageURLWWW.texture, new Rect(0, 0, imageURLWWW.texture.width, imageURLWWW.texture.height), Vector2.zero);  
             GetComponent<UnityEngine.UI.Image>().sprite = sprite;
         }
         yield return null;
     }

This script is attached to the UI.Image

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Paul_aranza · Oct 09, 2015 at 01:25 PM 0
Share

Bump guys. In the same pickle at the moment. Using Unity 5.2

avatar image Landern · Oct 09, 2015 at 01:50 PM 0
Share

Within the android manifest... have you defined the permissions for internet access?

 <uses-permission android:name="android.permission.INTERNET" /> 

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by John3D · Nov 30, 2016 at 02:08 PM

Your solution is here: http://answers.unity3d.com/questions/1175862/loading-a-sprite-from-url-c.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by palomo9314 · May 14, 2020 at 04:10 PM

@Requiem99 your code worked for me on android, THANK YOU A LOT I LOVE YOU! public Sprite spritex; public Image imagen; public Text texto;

 void Start()
     {
         
     }
     public void cargaimagen4(){
         StartCoroutine(RealLoadImage());
     }
 
 private IEnumerator RealLoadImage () {
          string url = "htttp://imagelocation.png";
          WWW imageURLWWW = new WWW(url);  
          texto.text+=url+"|";
          yield return imageURLWWW;        
          
          if(imageURLWWW.texture != null)
          {
              Debug.Log("texture bien"+url);
                 texto.text+="url valida";
              spritex = Sprite.Create(imageURLWWW.texture, new Rect(0, 0, imageURLWWW.texture.width, imageURLWWW.texture.height), Vector2.zero);  
              imagen.sprite=spritex;
              texto.text+="ya debio cargarse";
            
          }else{
              Debug.Log("texture null");
              texto.text+="null";
          }
          yield return null;
      }

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Facebook app invitation in android 0 Answers

How to display notification on notification bar using GCM in Unity? 1 Answer

Facebook app invitation in android -1 Answers

GUI.FocusControl not working in android? 0 Answers

Downloading an image displaying it won't work on Android 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges