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.
How I’m loading the image:
IEnumerator loadPictureEnumerator(string url, IUserProfile targetUser, System.Action<bool> callback)
{
WWW www = new WWW(url);
yield return www;
// Check for error
if (!String.IsNullOrEmpty(www.error)) {
callback.Invoke(false);
Logger.e(www.error);
} else {
// Convert to PNG with alpha channel
UnityEngine.Texture2D pngTex;
var bytes = ((UnityEngine.Texture2D) www.texture).EncodeToPNG();
pngTex = new Texture2D(128, 128, TextureFormat.ARGB32, false);
pngTex.LoadImage(bytes);
// Assign
switch (targetUser.GetType().ToString()) {
case "EyeBopCoSocial.UserProfile":
((EyeBopCoSocial.UserProfile) targetUser).image = pngTex;
break;
case "EyeBopCoSocial.LocalUser":
((EyeBopCoSocial.LocalUser) targetUser).image = pngTex;
break;
}
callback.Invoke(true);
}
}