티스토리 뷰


UnityWebRequest wwwTexture = UnityWebRequest.GetTexture(textureURL);
yield return wwwTexture.Send();
(...)
Texture2D imgToShare = DownloadHandlerTexture.GetContent(wwwTexture);

(...)

And then to save it :

Texture2D newImg = newTexture2D(imgToShare.width,imgToShare.height,TextureFormat.RGBA32,false);
newImg.SetPixels(imgToShare.GetPixels());
File.WriteAllBytes(somePath, newImg.EncodeToJPG());



1/ Download the texture

UnityWebRequest wwwTexture = UnityWebRequest.GetTexture(textureURL);
yield return wwwTexture.Send();
if(! wwwTexture.isError)
{
Texture2D texture = DownloadHandlerTexture.GetContent(wwwTexture);
(...)
}



2/ Create a new texture and then load the downloaded bytes inside the new texture (which will be readable)

Texture2D nexTexture = new Texture2D(texture.width, texture.height);
newTexture.LoadImage(wwwTexture.downloadHandler.data)


3/ Then you can use GetPixels() or EncodeToJPG() (or PNG) from the newTexture because it is readable.

File.WriteAllBytes(somePath, newTexture.EncodeToJPG());
Color[] colors = newTexture.GetPixels()

 

댓글
댓글쓰기 폼