Question by
suitmrt · Jan 16, 2019 at 03:08 PM ·
texture2dpngmemory usageruntime-generation
texture created at runtime twice as big as imported texture
The problem is, when I create a texture by reading bytes from a ".png" file - the texture created takes 2X memory, compared to the texture that was just dragged from assets to the "texture" property of raw image. The texture I'm dragging to raw image is the .png file imported to assets folder as ARGB32 with no mip-maps. I have tested both cases in the inspector separately, here is the code:
public RawImage rim;
public void CreateTexture()
{
string path = Application.streamingAssetsPath + "/Test.png";
byte[] byteArray = File.ReadAllBytes(path);
Texture2D tex2d = new Texture2D(2920, 2920, TextureFormat.ARGB32, false);
tex2d.LoadImage(byteArray);
rim.texture = tex2d;
}
How to decrease memory usage with runtime created textures, not imported ones (because, I need to download them from the internet)?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612185855im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Text to Texture2d / png 0 Answers
Texture 2D usage in the Memory Profiler skyrockets on Mac, 0 Answers
Creating new compressed textures on the fly and storing as PNG 0 Answers
Outline on Texture2D 1 Answer