Question

I have an PNG image with alpha, I need to convert it to BMP to be loaded to my OpenGL application. However, BMP has only 1 option for 32-bit, that is XRBG where 'X' is just an extra byte for padding purpose (4-byte alignment).

The question is how to ultilise this 'X' byte to contain alpha channel, so that the BMP (32-bit XRGB) can be loaded to GL application with transparent pixels?

Maybe I have to make my own tool to do this conversion? What I need is RGBA, and not 'XRGB' or 'ARGB', do I have to read the XRGB BMP file and scan pixel by pixel to convert to RGBA?

Which is the best way in VC++ if conversion is a must? Any software which can make transparent BMP?

Was it helpful?

Solution

pixelformer says that it can do it http://www.qualibyte.com/pixelformer/#color_depths

OTHER TIPS

You can use PixelFormer.

If you use ULW_ALPHA on UpdateLayeredWindow() & LoadImage(), the function expect the BMP file need to be 32-bit BGRA (with Premultiplied Alpha & Down-Top row order) other than that the function will not display bitmap correctly.

You can convert PNG to BMP 32-bit BGRA with PixelFormer (step 2).

  1. Open PixelFormer and click File > New:

enter image description here

  1. Then File > Export

enter image description here

P.S.:

Photoshop have broken support when exporting bmp with alpha channel (it can't do premultiply alpha, alpha channel value will become 0). You'll lose alpha channel but the BGR value will load correctly. You can still use Photoshop but must manually draw alpha on alpha channel tab.

Gimp also have broken support, when you export as bmp. LoadImage() will not load anything and you can't see the image. I suspect this problem caused by Gimp exporting BMP as Top-Down row order.

Visual Studio resource editor also have option to create/edit 32bpp BGR but doesn't support alpha channel

I once needed to do the same thing and wrote a small command line tool which can be found here.

Opersource softwares - ImageMagic or Gimp can also be used for this image conversion.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top