UnityWebRequest 获取图片代码

        IEnumerator GetTexture(string url, string width = "1024", string height = "1024")
        {
            UnityWebRequest GetTextureRequest = UnityWebRequest.Get(url);
            GetTextureRequest.SetRequestHeader("Content-Type", "application/json");
            yield return GetTextureRequest.SendWebRequest();
            if (GetTextureRequest.isDone)
            {
                Texture2D downloadTexture = new Texture2D(int.Parse(width), int.Parse(height));
                downloadTexture.LoadImage(GetTextureRequest.downloadHandler.data);
                VideoMipmap.sprite = Sprite.Create(downloadTexture, new Rect(0, 0, downloadTexture.width, downloadTexture.height), new Vector2(0, 0));
            }
            yield break;
        }

——————————————————————————————

【转载请注明文章出处】

猜你喜欢

转载自blog.csdn.net/weixin_42565127/article/details/126991874