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 DavidDebnar · Apr 15, 2012 at 07:38 PM · texture2dwwwwww.loadimageintotexture

www.LoadImageIntoTexture doesn't work?

Hey guys! I tried using www.LoadImageIntoTexture today, but all I got was a grey or really weird texture.

My code:

 var url : String;
 private var loaded : boolean = false;
 var texture : Texture2D;
 
 function OnGUI () {
     if(!loaded) {
         GUI.Label(Rect(20,20,300,20), "Enter the image url below and click load");
         url = GUI.TextField(Rect(20,40,Screen.width-40,20), url);
         if(GUI.Button(Rect(20,60,300,20), "Load")) {
             loaded = false;
             LoadImage();
         }
     }
     
     GUI.DrawTexture(Rect(20,80,100,100), texture, ScaleMode.StretchToFill);
 }
 
 function LoadImage () {
     texture = new Texture2D(16,16, TextureFormat.RGB24, false);
     while(true) {
         var www : WWW = WWW(url);
         yield www;
     }
     www.LoadImageIntoTexture(texture);
 }

Any ideas?

  • David

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

1 Reply

· Add your reply
  • Sort: 
avatar image
3
Best Answer

Answer by Lttldude · Apr 15, 2012 at 07:50 PM

This worked for me:

 var url : String;
 private var loaded : boolean = false;
 var texture : Texture2D;
 
 function OnGUI () {
     if(!loaded) {
        GUI.Label(Rect(20,20,300,20), "Enter the image url below and click load");
        url = GUI.TextField(Rect(20,40,Screen.width-40,20), url);
        if(GUI.Button(Rect(20,60,300,20), "Load")) {
        loaded = false;
        LoadImage();
        }
 }
     if(loaded)
     {
            GUI.DrawTexture(Rect(20,80,100,100), texture, ScaleMode.StretchToFill);
        }
 }
 
 function LoadImage () {
     texture = new Texture2D(16,16, TextureFormat.RGB24, false);
     var www = WWW(url);
     yield www;
     www.LoadImageIntoTexture(texture);
     loaded = true;
 }

I used this as a sample image: facebook_icon

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 DavidDebnar · Apr 15, 2012 at 07:55 PM 0
Share

Oh, right, the while(true) was destroying it. Thanks!

avatar image Fattie · May 04, 2014 at 01:34 PM 0
Share

Just FYI TextureFormat.DXT1 is a good performance tip on some platforms

avatar image UnityUser_1000 · Jul 30, 2016 at 08:00 PM 0
Share

Is there a simple way to adapt this so that the image loaded is used for the texture of a 3D object ins$$anonymous$$d of a GUI overlay element?

And aditionally, could this be modified simply to use an OpenFile Dialog to load the texture rather than a URL?

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

9 People are following this question.

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

Related Questions

Displaying an image from a resource folder. 2 Answers

LoadImageIntoTexture function on webplayer 0 Answers

Smooth Synchronized HD Video Playback 0 Answers

WWW not working to load image on iOS from google static maps. 0 Answers

What is the best way to persist www downloaded graphics? 1 Answer


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