Home > other >  How to reverse channel order of a Texture2D unity
How to reverse channel order of a Texture2D unity

Time:04-13

I need to convert a texture2D from having the normal RGBA channel order to BGRA channel order. I was originally hoping it would be as easy as

// Load image
Texture2D loaded = Resources.Load("zidane_640x640") as Texture2D;

// Convert from RGBA32 to BGRA32
Texture2D frame = new Texture2D(loaded.height, loaded.width, TextureFormat.BGRA32, false);
frame.SetPixels32(loaded.GetPixels32());
frame.Apply();

But that has no effect. I can't find a method anywhere to just switch the channel order for either Color[] or Texture2D. Is there any easy way to do this, or do I have to manually swap the channel order pixel by pixel?

CodePudding user response:


It works fine. You just made a typo there.

Texture2D frame = new Texture2D(loaded.width, loaded.height, TextureFormat.BGRA32, false);

Alternatively:

Graphics.ConvertTexture( src , dst );

  • Related