Search Unity

Downloaded sprite texture gets white tint

Discussion in 'General Graphics' started by kennyrogers7272, Apr 7, 2017.

  1. kennyrogers7272

    kennyrogers7272

    Joined:
    Jan 22, 2015
    Posts:
    38
    When I use the following code to download a .jpg or .png image from my server, it appears in Unity as being heavily tinted to whatever color is set in the inspector for the UI image. It was my understanding that using the values 255 255 255 255 would apply no tint. See code, see image.

    private IEnumerator LoadImage()
    {
    Texture2D temp = new Texture2D(0,0);
    WWW www = new WWW("https://bigfatsimulations.com/tmp/am3d2_available/newGameImage.jpg");
    yield return www;

    temp = www.texture;
    Sprite sprite = Sprite.Create(temp, new Rect(0,0,temp.width, temp.height), new Vector2(0.5f,0.5f));
    Transform thumb = transform;
    thumb.GetComponent<Image>().sprite = sprite;
    }

    Others have this issue:
    http://answers.unity3d.com/questions/987299/sprite-tint.html
     

    Attached Files:

    Last edited: Apr 12, 2017
  2. kennyrogers7272

    kennyrogers7272

    Joined:
    Jan 22, 2015
    Posts:
    38
    I opened a new project and the image loads perfectly. In my main project however, the downloaded image appears white tinted in the UI Image.
     
    Last edited: Apr 12, 2017
  3. Kancullo

    Kancullo

    Joined:
    May 15, 2017
    Posts:
    2
    I have the same problem, any solution?
     
  4. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    3,276
    Is your project set to linear Color space? then the www class is expecting linear textures from you but your are giving it gamma space images.
    If you import the same texture inside the editor unity does expect that the most images you supply are gamma space except if you tell it is not (by unchecking the sRGB (Color Texture) checkbox in the texture importer settings).
     
  5. Kancullo

    Kancullo

    Joined:
    May 15, 2017
    Posts:
    2
    Hi! I just found a solution that works for me.

    When you just download the image with WWW, just create a new texture2D with the widht and height of the text downloaded and fill with the data of it. Select the texture format of your choose, midmaps, and the last parameter are if the image is linear or gamma, play with this parameter changing it.

    There is an example:
    Texture2D textureToFill = new Texture2D(temp.texture.width, temp.texture.height,TextureFormat.RGB24,false, false);
    textureToFill.LoadImage(temp.bytes);
    Sprite sprite = Sprite.Create (textureToFill, new Rect (0, 0, textureToFill.width, textureToFill.height), Vector2.zero);