Quantcast
Channel: Questions in topic: "readable"
Viewing all articles
Browse latest Browse all 62

UnityWebRequest.GetTexture and EncodeToPNG

$
0
0
Hi friends! I need to ask you about this error with the UnityWebRequest.GetTexture function. I have a code with the WWW class to get image from Azure, then I create sprites from this images and use them in the game. And before leave the scene, I need to save some of this sprites with EncodeToPng. All my code with the WWW class works. It´s something like this: DownloadTexture(){ WWW www = new WWW (url); yield return www; Texture2D tex = new Texture2D (1, 1); www.LoadImageIntoTexture(tex); Sprite image = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (0.5f, 0.5f)); someGameObject.sprite = image; } SaveSprite() { byte []bytes = someGameObject.sprite.texture.EncodeToPNG (); } I changed some variables and some stuff for simplify the case. With this code works perfect, but it´s a big data manage scene, so I tried UnityWebRequest for better performance. With the new WebRequest the performance is much better so I want to preserve this method, but When I try to save my sprites I have the error "Texture2D is not Readable" And don´t know how to change it. My new code is just a WWW to WebRequest change: DownloadTexture(){ UnityWebRequest www = UnityWebRequest.GetTexture(url); yield return www.Send(); tex = new Texture2D (1, 1); tex = ((DownloadHandlerTexture)www.downloadHandler).texture; Sprite image = Sprite.Create (tex, new Rect (0, 0, tex.width, tex.height), new Vector2 (0.5f, 0.5f)); someGameObject.sprite = image; } SaveSprite() { byte []bytes = someGameObject.sprite.texture.EncodeToPNG (); } Now I get my sprites I can play with them but can´t save them in local. Does Anyone know how to save this in some other way or make the texture readable or something? Thanks for your help! Have a good day! Gabriel

Viewing all articles
Browse latest Browse all 62

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>