unity运行时www下载的texture图片转换成sprite赋值到image上

IEnumerator ImageTexture(string url)

    {

//下载图片资源

        WWW www = new WWW(url);

//等待下载完成

        yield return www;
//

        Texture2D tex = new Texture2D(www.texture.width, www.texture.height);

//加载图像到纹理

        www.LoadImageIntoTexture(tex);

//赋值给自己

        transform.GetComponent().sprite = Sprite.Create(tex, new Rect(0, 0, www.texture.width, www.texture.height), Vector2.zero);
        yield return null; 
    }

你可能感兴趣的:(个人,unity,杂项)