• 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
Question by Hoskins355 · Jan 08, 2016 at 04:25 PM · texture2dimagewwwloadimageintotexture

How do you download image to UI.Image?

T$$anonymous$$s is as far as I got

 IEnumerator downloadImg (string url){
         WWW www = new WWW(url);
         yield return www;
         Texture2D texture = new Texture2D(1, 1);
         www.LoadImageIntoTexture (texture);
 
         Sprite sprite = Sprite.Create (texture, new Rect (0, 0, texture.width, texture.height), new Vector2 (0.5f, 0.5f));
         imagePrefabClone.GetComponent<Image>().sprite = sprite;
     }
 

But for some reason the sprite is not getting set. Any ideas?

Comment

People who like this

0 Show 0
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

4 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Hoskins355 · Jan 07, 2016 at 10:20 PM

T$$anonymous$$s got it working

 IEnumerator isDownloading(string url){
         // Start a download of the given URL
         var www = new WWW(url);            
         // wait until the download is done
         yield return www;
         // Create a texture in DXT1 format
         Texture2D texture = new Texture2D(www.texture.width, www.texture.height, TextureFormat.DXT1, false);
         
         // assign the downloaded image to sprite
         www.LoadImageIntoTexture(texture);
         Rect rec = new Rect(0, 0, texture.width, texture.height);
         Sprite spriteToUse = Sprite.Create(texture,rec,new Vector2(0.5f,0.5f),100);
         imageToDisplay.sprite = spriteToUse;
 
         www.Dispose();
         www = null;
     }
Comment
ceceomer
PAHeartBeat
Josewdf

People who like this

3 Show 0 · 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

Answer by mamad_m2 · Feb 11, 2020 at 11:37 AM

You can do it easily with Davinci
The library has a simple usage and supports Unity UI.Image and 3D model textures.

 Davinci.get().load(imageUrl).into(image).start();

Hope t$$anonymous$$s helps!

Comment
ApenasVB
Saman96

People who like this

2 Show 3 · 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 fafase · Feb 11, 2020 at 02:00 PM 0
Share

Why would you use an external library when it can easily be done with Unity?

avatar image mamad_m2 fafase · Feb 11, 2020 at 03:41 PM 0
Share

It's not an external library. It has a simple c# script that written for unity and has a lot of benefits and features like fading animation and process callbacks. Take a look at its that page. You don't have to reinventing the wheel, cause 'time' is matters ;)

avatar image dmlo · May 09, 2020 at 12:17 PM 0
Share

Wow that's a cool project And your art style is really fantatastic-looking too

avatar image

Answer by samra2494 · Nov 01, 2017 at 11:40 AM

I t$$anonymous$$nks helpful for you.

//here is the code

string WebUrl , ServerUrl; public Image Web_image , ServerImage; Texture2D tex; WWW Link;

 IEnumerator LoadImageInternet()
 {
     tex = new Texture2D(4, 4, TextureFormat.DXT1 , false);
     Link = new WWW (WebUrl);
     yield return Link;
     Link.LoadImageIntoTexture (tex);
     Web_image.sprite = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (0, 0)); 
 }

 //Button Event
 public void LoadFromInternet()
 {
     WebUrl = "https://upload.wikimedia.org/wikipedia/commons/d/dc/Cats_Petunia_and_Mimosa_2004.jpg";
     StartCoroutine (LoadImageInternet ());
 }
Comment

People who like this

0 Show 0 · 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

Answer by Josewdf · Feb 13, 2021 at 10:29 AM

Now in 2021 Unity recommend t$$anonymous$$s code that is more efficient and also worked perfectly.

 //PlayGamesPlatform.Instance.GetUserImageUrl() Used to get player Image from Google Play Games
 
 using UnityEngine.Networking;

     private IEnumerator GetPlayerImage(string url)
         {
             UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
             yield return www.SendWebRequest();
     
             Texture2D myTexture = DownloadHandlerTexture.GetContent(www);
     
             Rect rec = new Rect(0, 0, myTexture.width, myTexture.height);
             Sprite spriteToUse = Sprite.Create(myTexture, rec, new Vector2(0.5f, 0.5f), 100);
     
             playerImage = spriteToUse;
         }
 
 
 
 
 
 
 
Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 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

Related Questions

!texture.texture error 0 Answers

Error Trying to Download a Image from a Local File 1 Answer

How do I progressively download images with WWW. 1 Answer

Image is not loading into Texture 0 Answers

Detect WWW Image bitmap dimensions? 2 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