Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

(Fixed in b19) Masking JPG image

Discussion in 'UGUI & TextMesh Pro' started by pea, Sep 23, 2014.

  1. pea

    pea

    Joined:
    Oct 29, 2013
    Posts:
    98
    Seems I can't mask a JPG image that's loaded in at runtime. I've tried converting it to a format with alpha channel, but no dice. Bug or am I doing it wrong (again)?

    The image loads fine, converts to PNG fine, but shows as a hard square, without the rounded corners of the mask.

    "Profile Pic Mask" is a PNG sprite with transparency (rounded corners). "Profile Pic" is a JPG Facebook profile image.

    Screen Shot 2014-09-24 at 10.04.23 am.png

    How I'm loading the image:

    Code (csharp):
    1. IEnumerator loadPictureEnumerator(string url, IUserProfile targetUser, System.Action<bool> callback)
    2.         {
    3.             WWW www = new WWW(url);
    4.             yield return www;
    5.             // Check for error
    6.             if (!String.IsNullOrEmpty(www.error)) {
    7.                 callback.Invoke(false);
    8.                 Logger.e(www.error);
    9.             } else {
    10.                 // Convert to PNG with alpha channel
    11.                 UnityEngine.Texture2D pngTex;
    12.                 var bytes = ((UnityEngine.Texture2D) www.texture).EncodeToPNG();
    13.                 pngTex = new Texture2D(128, 128, TextureFormat.ARGB32, false);
    14.                 pngTex.LoadImage(bytes);
    15.              
    16.                 // Assign
    17.                 switch (targetUser.GetType().ToString()) {
    18.                     case "EyeBopCoSocial.UserProfile":
    19.                         ((EyeBopCoSocial.UserProfile) targetUser).image = pngTex;
    20.                         break;
    21.                     case "EyeBopCoSocial.LocalUser":
    22.                         ((EyeBopCoSocial.LocalUser) targetUser).image = pngTex;
    23.                         break;
    24.                 }
    25.                 callback.Invoke(true);
    26.             }
    27.         }
    Screen Shot 2014-09-24 at 10.05.59 am.png Screen Shot 2014-09-24 at 10.06.19 am.png
     
  2. pea

    pea

    Joined:
    Oct 29, 2013
    Posts:
    98
    In fact, taking the remote image loading out of the equation it still doesn't work. If I set a texture on the Raw Image it still just shows without the mask, both in Scene and Game views, no matter which platform I'm publishing to.

    Mask with transparency at corners:
    Screen Shot 2014-09-24 at 11.15.11 am.png

    With Raw Image as child of it:
    Screen Shot 2014-09-24 at 11.15.17 am.png
     
  3. pea

    pea

    Joined:
    Oct 29, 2013
    Posts:
    98
    Just updated to beta 19. Working now! :)