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 /
avatar image
0
Question by Benn13 · Mar 15, 2020 at 11:51 AM · wwwimagestextureimporterimage loaderwww.loadimageintotexture

Loading some images doesn't work

I'm working on a Tool, for which users can load in images locally from their computer. However, some images appear to be converted in such a way, that Unity can't load them into the game. I'm using WWW for loading Images locally, though I've also tried using UnityWebRequest and File.ReadAllBytes and all of them resulted in loading the white picture with a red questionmark (error-texture). The picture in question was exported/created with AffinityPhoto as jpg. Also: Most images seem to work (at least for me)

         if (!string.IsNullOrEmpty(path))
         {
             WWW www = new WWW(path);
             currentlyLoadedSprite = Sprite.Create(www.texture, new Rect(0, 0, www.texture.width, www.texture.height), Vector2.one * 0.5f);
             SetImagesToCurrentSprite();
         }
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
0

Answer by Link17x · Mar 15, 2020 at 12:26 PM

I think WWW is depreciated, and you should use UnityWebRequest. But I'm not sure if you need UnityWebRequest if you're only getting images locally? You could use the UnityWebRequest to fetch images from online using a URL. If you decide to use this,

 // Use IEnumerator so you can yield
 // which waits till you have the image before proceeding
 private void IEnumerator()
 {
   use var getImage = UnityWebRequest.Get(your URL);
   
   yield return getImage.SendWebRequest();
 
   // Do something with your image (this is in bytes)
 }


 private void SetImages(List<byte[]> images)
 {
     for (var i = 0; i < images.Count; i++)
     {
        // Texture size doesn't matter, it will be changed by the loaded image anyway
        var texture = new Texture2D(1, 1);
        texture.LoadImage(images[i]);
     
        var img = Instantiate(imagePrefab, pos, Quaternion.identity, transform);
        img.GetComponent<Renderer>().material.mainTexture = texture;
     }
 }


I don't really know what you want to do with your image, this is an example if you were to use the image on a game object and I think you need to use RawImage component on a quad or something if you decide to do that. Just bear in mind the image should be loaded in bytes, and you might need to create some texture using those bytes, rather than simply loading an image in and setting it.

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

126 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

Related Questions

Save a downloaded image 1 Answer

Integrated VideoPlayer component but for images? 0 Answers

How can I upload a PNG to imgur and save its URL? 2 Answers

Run a coroutine when there is spare time 0 Answers

Question: Is it possible to create an image out of an HTML canvas in unity using c#? 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