- Home /
Losing sprite quality when load .png from url
Hi everyone. I have problem with sprite quality after load png file from url. I use this code to load and set sprite on Image
private IEnumerator RealLoadImage (string url, UnityEngine.UI.Image imageView) {
if (imageCashe.ContainsKey (url)) {
if (imageView != null) {
imageView.sprite = imageCashe[url];
}
} else {
//Call the WWW class constructor
WWW imageURLWWW = new WWW (url);
//Wait for the download
yield return imageURLWWW;
//Simple check to see if there's indeed a texture available
if(imageURLWWW.error == null){
if (imageURLWWW.texture != null) {
//Construct a new Sprite
Sprite sprite = new Sprite ();
Texture2D image = new Texture2D(imageURLWWW.texture.width, imageURLWWW.texture.height, TextureFormat.ARGB32, true);
imageURLWWW.LoadImageIntoTexture(image);
image.SetPixels( image.GetPixels(0,0,image.width,image.height));
image.filterMode = FilterMode.Bilinear;
image.alphaIsTransparency = true;
image.Apply();
sprite = Sprite.Create(image, new Rect (0, 0, image.width, image.height), new Vector2(0,0));
if(!imageCashe.ContainsKey(url))
{
imageCashe.Add (url, sprite);
}
//Assign the sprite to the Image Component
if (imageView != null)
{
imageView.sprite = sprite;
}
}
}
else
{
Logger.LogError("Error to load img with url - " + url);
// делаем image прозрачным
imageView.color = new Color(255,255,255,0);
}
imageURLWWW.Dispose ();
imageURLWWW = null;
}
imageView.enabled = true;
yield return null;
}
and get this result
But, if I download this png file manual, move on resource and set this file on image, i get this
Why so big different with this sprites? And how get smooth sprite on dynamic load? Version Unity 5.4.0f3 and last version 5.6 get this problem too. Thanks a lot)
Answer by GravyGaming · Aug 31, 2017 at 08:19 PM
I'm having the same problem, and I couldn't found any solution yet, anyone can help with this?
Your answer
Follow this Question
Related Questions
Best texture compression: TinyPNG + Unity sprite Packer? 1 Answer
How do you crop a Texture2d 1 Answer
Unity UpdateExternalTexture from MovieTexture windows crash 0 Answers
2D sprite renders a small part of another one with "Sprite Mode : Multiple" 0 Answers
Resize a sprite by giving it more transparent pixels 0 Answers