Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unity3d 为什么纹理的文件图像大小与在Unity中加载时的大小不同?_Unity3d - Fatal编程技术网

Unity3d 为什么纹理的文件图像大小与在Unity中加载时的大小不同?

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

当我使用5.01KB的纹理“Texture2D.LoadTexture()”时,我期望大约8KB。 但是这个内存分配是2.8MB

为什么纹理alloc内存更大

示例代码

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)来降低内存占用