Search Unity

Why www.LoadImageIntoTexture takes forever for certain alpha channels in png?

Discussion in 'Scripting' started by Elandir, Feb 20, 2018.

  1. Elandir

    Elandir

    Joined:
    Feb 9, 2014
    Posts:
    32
    Hi there.

    Well, actually, not forever but for a very long time (particularly if compared with others which seems similar).

    First, I'm not sure if this is the proper board for this question (I'm not sure if my problem comes from the script or from the png files format). I apologize in advance if this is the wrong place.

    The issue here is that I'm loading a set of textures (about 20) and I'm using this Coroutine:

    Code (CSharp):
    1.   IEnumerator CR_GetTexture(string pathToLoad, int key, Dictionary<int, Texture> targetDictionary)
    2.     {
    3.        
    4.         string modifiedPathToLoad = "file:///" + pathToLoad.Replace("\\", "/");
    5.         Texture2D tex;
    6.  
    7.         tex = new Texture2D(4, 4, TextureFormat.DXT5, false);
    8.  
    9.         tex.wrapMode = TextureWrapMode.Clamp;
    10.  
    11.  
    12.         WWW www = new WWW(modifiedPathToLoad);
    13.  
    14.         while (!www.isDone)
    15.         {
    16.             yield return null;
    17.         };
    18.        
    19.  
    20.  
    21.         www.LoadImageIntoTexture(tex);
    22.        targetDictionary.Add(key, tex);      
    23.     }
    Is working properly for png files with no alpha channel but when I try to load png files with alpha channel I have very different loading times (from a few seconds to >90)and I can't find the reason. Find next a couple of example textures:

    FastLoad.png Are loading in a few seconds, more or less as fast as our images with no alpha channel at all.

    SlowLoad.png Are loading in a much longer time, above 90 seconds.

    Note that both pictures are generated from the same source file and the only real difference is how I made the alpha channel (free hand with a brush in the first one, selecting by color 'black' and then clearing it the second).


    So... any idea about what could be causing this weird long loading time for the second when calling www.LoadImageIntoTexture??

    Cheers