Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
4
Question by blazeaster · Apr 23, 2016 at 07:46 PM · c#spriteloadingurl

Loading a sprite from URL C#

I'm trying to load an image from an URL, but none of the answers i found online apply to my problem. There is a good example in the unity docs, but it's javascript:

http://docs.unity3d.com/ScriptReference/WWW.LoadImageIntoTexture.html

I than need to load this sprite onto UI image element.

Please help,

Thanks

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
25

Answer by blazeaster · Apr 25, 2016 at 05:26 PM

Solved thanks to the The Little Guy from unity forums!

    public class ExampleClass : MonoBehaviour {
  
     // The output of the image
     public Image img;
  
     // The source image
     public string url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg";
  
     IEnumerator Start() {
         WWW www = new WWW(url);
         yield return www;
         img.sprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), new Vector2(0, 0));
     }
 }

Comment
Add comment · 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 John3D · Nov 30, 2016 at 01:56 PM 0
Share

Thanks for the solution. Works perfectly!

avatar image deltron1830 · Jan 12, 2017 at 08:01 PM 3
Share

Great answer. I did not know until now that Start (and other event handlers) can be made return IEnumerator and will be run as coroutines. Thats awesome!!

avatar image freedom667 · Feb 16, 2018 at 12:10 PM 0
Share

can be Resources.Load with URL? because I have a lot of pictures

avatar image
3

Answer by idbrii · Oct 31, 2018 at 11:29 PM

Instead of Sprite.Create, you may want to use WWW.LoadImageIntoTexture to ensure your image isn't downsampled by QualitySettings (the difference is very noticeable at "Eighth Res").

 www.LoadImageIntoTexture(img.mainTexture as Texture2D);

Comment
Add comment · Show 1 · 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 A1A_PW · Nov 02, 2018 at 05:52 PM 0
Share

This works great in combination with the top comment!

avatar image
2

Answer by creativeConny · Oct 26, 2017 at 12:45 PM

I wonder if there is any option to auto scale the aspect ratio of the downloaded image? In my case there is a placeholder with 800x600 pixels. So I want to keep the downloaded image's aspect ratio but cap its size to 800x600? Right now unity tries to fill my placeholder to its max...

EDIT: Ok found the solution by my self: At first I had not any source file in my image object. This caused the "preserve aspect ratio" button to not appear. After I inserted a placeholder image (before uploading one) the button appeared. Then just simply turn it on, now every time you upload a new image from url it keeps its aspect ratio! :)

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

166 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Saving/loading inherited class scripts (C#) 1 Answer

Random Layout of tiles notworking in 2d game 1 Answer

Material of last four, is set to the first four in the selection. 1 Answer

Intances with Public Static, or at least somehting similar 1 Answer

How can i put down a sprite on collision? 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