- Home /
I use WWW to display a jpg file, but it display a wrong image ?
i try to display this jpg (http://www.jxysh.cn/upload/1409091854047652145.jpg), but it display a wrong image
WWW www = new WWW("http://www.jxysh.cn/upload/1409091854047652145.jpg") ; StartCoroutine(WaitForWWWLoadImg(www);
... img.mainTexture = www.texture; //a wrong image
I also try tex.LoadImage(www.bytes) //wrong too
Answer by sarthakshah · Sep 18, 2014 at 04:59 AM
Below script is working for my png files, so just change your file extestion from jpg to png on server, and also change in url of below script, Hope this will work.
using UnityEngine;
using System.Collections;
public class image : MonoBehaviour {
Texture myImage;
// Use this for initialization
void Start () {
string url="http://www.jxysh.cn/upload/1409091854047652145.jpg";
StartCoroutine (getImage (url));
}
IEnumerator getImage (string url)
{
print ("Started");
WWW www = new WWW (url);
yield return www;
//In myImage u will get your image
myImage = www.texture;
gameObject.renderer.material.mainTexture = myImage;
}
}
That doesn't help at all, since the problem is not the extension or the code. Changing the extension makes no sense since Unity can load jpg images fine, as long as they are valid. The problem is that the image is C$$anonymous$$Y$$anonymous$$ and Unity can only use RGB.
Its an alternative, not solution,
If i have C$$anonymous$$Y$$anonymous$$ image , so what will be the solution?
Changing C$$anonymous$$Y$$anonymous$$ to RGB , is a solution?
The code won't be anything, since Unity doesn't support C$$anonymous$$Y$$anonymous$$ images. You're correct that changing the extension won't do anything; you'd have to load it into Photoshop and re-save it as RGB.
but if the image which comes from server , and its in C$$anonymous$$Y$$anonymous$$ , then what?
i think we can't change it at runtime.
but if the image which comes from server , and its in C$$anonymous$$Y$$anonymous$$ , then what?
Then you're screwed. ;) I guess you could write your own image loader for C$$anonymous$$Y$$anonymous$$ images, but that's kind of a last resort if you were being forced to use C$$anonymous$$Y$$anonymous$$ for some strange reason. I think it would be a lot simpler just to stick to RGB images in the first place; C$$anonymous$$Y$$anonymous$$ is only used for printing and doesn't really have any place on the web.
Your answer
Follow this Question
Related Questions
Any way to show a picture on the screen when a model is clicked? 2 Answers
Is it possible to edit description field of jpg when saving screenshot? 2 Answers
Load image in runtime from jpg 1 Answer
Include jpg files without automatically converting to sprites or textures 1 Answer
use jpg in unity3d 2 Answers