我有一个以ETC_RGB4
格式表示的Textured2D
,我该如何将其更改为其他格式?比如RGBA32
。基本上我想从3通道切换到4通道,并且从每个通道的4位切换到8位。
谢谢
我有一个以ETC_RGB4
格式表示的Textured2D
,我该如何将其更改为其他格式?比如RGBA32
。基本上我想从3通道切换到4通道,并且从每个通道的4位切换到8位。
谢谢
您可以在运行时更改纹理格式。
1。创建一个新的空 Texture2D
,并将RGBA32
提供给TextureFormat
参数。这将创建一个带有RGBA32
格式的空纹理。
2。使用Texture2D.GetPixels
获取旧纹理(格式为ETC_RGB4
)的像素,然后使用Texture2D.SetPixels
将这些像素放入从步骤 #1 中新创建的纹理中。
3。调用Texture2D.Apply
应用更改。就是这样。
一个简单的扩展方法:
public static class TextureHelperClass
{
public static Texture2D ChangeFormat(this Texture2D oldTexture, TextureFormat newFormat)
{
//Create new empty Texture
Texture2D newTex = new Texture2D(2, 2, newFormat, false);
//Copy old texture pixels into new one
newTex.SetPixels(oldTexture.GetPixels());
//Apply
newTex.Apply();
return newTex;
}
}
使用方法:
public Texture2D theOldTextue;
// Update is called once per frame
void Start()
{
Texture2D RGBA32Texture = theOldTextue.ChangeFormat(TextureFormat.RGBA32);
}
GetRawTextureData
返回一个字节数组,而不是所提到的ETC_RBG4
。这里有什么我没有理解的吗? - Swift