Unity3d 为什么纹理的文件图像大小与在Unity中加载时的大小不同?
当我使用5.01KB的纹理“Texture2D.LoadTexture()”时,我期望大约8KB。 但是这个内存分配是2.8MB 为什么纹理alloc内存更大 示例代码Unity3d 为什么纹理的文件图像大小与在Unity中加载时的大小不同?,unity3d,Unity3d,当我使用5.01KB的纹理“Texture2D.LoadTexture()”时,我期望大约8KB。 但是这个内存分配是2.8MB 为什么纹理alloc内存更大 示例代码 private Texture2D[] m_SaveTextures = null; public void Start() { string path = "../Directory/"; m_SaveTextures = new Texture2D[] { Get
private Texture2D[] m_SaveTextures = null;
public void Start()
{
string path = "../Directory/";
m_SaveTextures = new Texture2D[]
{
GetTexture(path + "Red.png"),
GetTexture(path + "Green.png"),
GetTexture(path + "Blue.png"),
GetTexture(path + "Black.png")
};
}
private Texture2D GetTexture(string path)
{
if (!File.Exists(path)) return null;
var texture = new Texture2D(1, 1, TextureFormat.ARGB32, false)
{
name = Path.GetFileNameWithoutExtension(path)
};
texture.LoadImage(File.ReadAllBytes(path));
return texture;
}
示例图像
Unity分析器检查图像
因为png是一个压缩的图像文件,但加载到其中的纹理不是
TextureFormat.ARGB32
不是压缩格式,因此内存成本为每像素32位
如果您的目标平台支持,您可以使用一种压缩格式(如DXT5)来降低内存占用