I have a Textured2D
loaded which is represented in ETC_RGB4
how can I change this to another format? say RGBA32
. Basically I want to switch from 3 channels to 4 and from 4 bit per channel to 8 per channel.
Thanks
You can change texture format during run-time.
1.Create new empty Texture2D
and provide RGBA32
to the TextureFormat
argument. This will create an empty texture with the RGBA32
format.
2.Use Texture2D.GetPixels
to obtain the pixels of the old texture that's in ETC_RGB4
format then use Texture2D.SetPixels
to put those pixels in the newly created Texture from #1.
3.Call Texture2D.Apply
to apply the changes. That's it.
A simple extension method for this:
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;
}
}
USAGE:
public Texture2D theOldTextue;
// Update is called once per frame
void Start()
{
Texture2D RGBA32Texture = theOldTextue.ChangeFormat(TextureFormat.RGBA32);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With