Search code examples
c#c++unity-game-enginefreeimage

With FreeImage is it possible to have ConvertToRawBits output in ARGB32 or RGBA32 rather than BGRA32?


I'm loading in a PNG to use as a texture in Unity. When I use ConvertToRawBits() it outputs to BGRA32. Is it possible to output to ARGB32 or RGBA32 instead?

https://gist.github.com/ciwolsey/24635ea523b4a6b758783688be53bf86


Solution

  • You have two options for this, you can:

    1. Recompile Freeimage with FREEIMAGE_COLORORDER set to FREEIMAGE_COLORORDER_RGB value (1). Then your loaded images will be always in RGBA32 format. If this FREEIMAGE_COLORORDER is not specified at compile time, the actual color order setting is determined from the target system's endianess.

    2. Use Freeimage SwapRedBlue32 function to convert loaded image from BGRA32 to RGBA32 format.

    Here is a nice discussion on this subject.