- Home /
 
               Question by 
               Patrick31415 · Aug 06, 2019 at 02:19 AM · 
                create a texture  
              
 
              How to load a PNG into texture2d without extra memory?
I try to load a PNG file into Texture2D. But I found the texture2D got extra memory in Profiler. This is the code:
 WWW www = new WWW("file:///F:/1000.png");    // 256*256 RGB, no Alpha channel. The memory should be 192KB.
 Texture2D tex = new Texture2D(0, 0, TextureFormat.RGB24, false);
 www.LoadImageIntoTexture(tex);                 // 448KB in Profiler. (448=192+256)
 tex.wrapMode = TextureWrapMode.Clamp;
GC.Collect() can't fix the problem. How to cut the extra memory 256KB?
               Comment
              
 
               
              Answer by xxmariofer · Aug 06, 2019 at 06:24 AM
Test ussing the UnityWebRequest should be more efficient
         using (UnityWebRequest www = UnityWebRequestTexture.GetTexture("file:///F:/1000.png"))
         {
             yield return uwr.SendWebRequest();
 
             if (uwr.isNetworkError || uwr.isHttpError)
             {
                 Debug.Log(uwr.error);
             }
             else
             {
                 // Get downloaded asset bundle
                 var tex  = DownloadHandlerTexture.GetContent(www);
             }
         }
Your answer
 
 
             Follow this Question
Related Questions
Texture3D stays black no matter what? 1 Answer
Textures are Missing 1 Answer
Hexagonal Grids 2 Answers
What is the best way to create a simple colored plane object in NGUI? 1 Answer
How to create Sprite from loaded texture 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                