public static Sprite getCustomAvatar() { getprofilepicture cust = new getprofilepicture(getEmail(), getToken(), getID(), "getCustomAvatar"); string json = JsonConvert.SerializeObject(cust); Byte[] data = System.Text.Encoding.ASCII.GetBytes(json); stream.Write(data, 0, data.Length); data = new Byte[16000000]; string responseData = string.Empty; Int32 bytes = stream.Read(data, 0, data.Length); responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); Texture2D imagetexture = new Texture2D(100, 100); bool success = imagetexture.LoadImage(Convert.FromBase64String(responseData)); if (success) { Debug.Log("Image conversion successful"); } else { Debug.Log("Image conversion failed"); } imagetexture.Apply(true); Sprite imagesprite = Sprite.Create(imagetexture, new Rect(0, 0, imagetexture.width, imagetexture.height), new Vector2(.5f, .5f)); return(imagesprite); }
public static Sprite getOtherCustomAvatar(string email) { getprofilepicture cust = new getprofilepicture(email, getToken(), getID(), "getCustomAvatar"); string json = JsonConvert.SerializeObject(cust); Byte[] data = System.Text.Encoding.ASCII.GetBytes(json); stream.Write(data, 0, data.Length); data = new Byte[100000]; string responseData = string.Empty; Int32 bytes = stream.Read(data, 0, data.Length); responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes); Texture2D imagetexture = new Texture2D(100, 100); imagetexture.LoadImage(Convert.FromBase64String(responseData)); imagetexture.Apply(); Sprite imagesprite = Sprite.Create(imagetexture, new Rect(0, 0, imagetexture.width, imagetexture.height), new Vector2(.5f, .5f)); return(imagesprite); }