About using WWW to downloading image from server

Hi guys !

So my problem is I got this link http://viss.gonct.info/viss/res/images/banner/nplay/Chia-se-Nplay-Detail.png

Then I use www to download from this link and save into file.

           WWW w = new WWW (url);

            yield return w;

            if (string.IsNullOrEmpty (w.error)) { // No Error
                if(!isForceDownload){
                    try{
                        fl.WriteAllBytes( Application.persistentDataPath + "/" + name + ext , w.texture.EncodeToPNG() );
                    }catch(IOException e){
                        GameService.Log(e.StackTrace);
                        GameService.Log(e.Message);
                    }catch(System.Exception e){
                        GameService.Log (e.StackTrace);
                        GameService.Log (e.Message);
                    }
                }
                Texture2D tex = new Texture2D (1, 1);
                w.LoadImageIntoTexture(tex);
                callback (tex);
            } else {
                GameService.Log("Error downloading : " + url );
                GameService.Log("Error message : " + w.error);
            }

Then I also create Sprite from this Texture

ImageDownloader.GetImage(arg1._data.image_large,delegate(Texture obj) {
                _large.sprite = Sprite.Create( obj as Texture2D,
                                              new Rect( 0 , 0 ,obj.width , obj.height),
                                              new Vector2(0.5f, 0.5f),
                                              100,
                                              0,
                                              SpriteMeshType.FullRect);

And my downloaded texture look like this

So what happen to me ? Am I make something wrong here ?

Thanks.

Weird, your code works fine for me. Both downloaded file on the disc and sprite on the scene look as expected.

I noticed your file is a png. Sometimes different engines render png’s very differently because they can contain alpha information and “invisible” colors. Try saving as a jpg and try again.

Can I ask which version of Unity that you are using ? I’m using the lastest one on windows

Lets me try to change it.

it weird that I can download this image

http://viss.gonct.info/viss/res/images/banner/nplay/giovang_detail.png

And get it right. But another isn’t

Oh, sorry, it was 4.6.6 (windows), will try it on 5.1.1

The original image link is:

Chia-se-Nplay-Detail.png: PNG image data, 924 x 417, **8-bit colormap**, non-interlaced

The bad one you attached is:

Chia-se-Nplay-Detail.png: PNG image data, 924 x 417, **8-bit/color RGBA**, non-interlaced

So it seems that the image is being interpreted as having a different color map than it should (RGBA) ??

So I think the problem is Unity v5.1.1f , since I switch back to older version of unity it is working fine !

Probably best to submit a bug report (include a project that shows the issue and indicate that it works ok in an older version).