It makes me wonder where in the png file that info is stored, and how it is stored. It would be cool if it were straight forward enough and you could just open the png, read that data, find the transparency coding, and convert it to use in your program.
Pete
Easy peasy for PNG files!
First, you need to understand that PNG files write data in CHUNKS. Basically, you have the file header (one chunk of info with size, color mode, ect stored), and then other chunks come later (perhaps palette, or author info, or the actual pixel data...)
Each of these chunks has a 4 byte identifier to them. "IHDR" is the image header. "PLTE" is the color palette, if one is used (say for 256 color images). "IDAT" is the pixel data and "IEND" is the end of data.
Read a chunk identifier, if it's not the one you're interested in, skip its data and read the next chunk header until you find the one you're looking for -- they can be in ANY order (more or less), so don't assume the 4th chunk is what you need just because you found the info there once, for one image.
The one you'd want is "bKGB".
The bKGD chunk specifies a default background colour to present the image against. If there is any other preferred background, either user-specified or part of a larger page (as in a browser), the bKGD chunk should be ignored. The bKGD chunk contains:
For Color types 2 and 6 (RGB32 and RGBA32 images:
Red 2 bytes
Green 2 bytes
Blue 2 bytes
For colour types 2 and 6 (truecolour, truecolour with alpha), the values are the colour to be used as background, given as RGB samples in the range 0 to (2bitdepth)-1.
**********************
So basically, open the file for binary. Read a chunk to get the identifier. When you find "kBGD", you've found the color used for the image background.
And, to make it even easier, if you look in my SaveImage library, there's already a basic LoadPNG routine which reads and displays chunk headers and info for us. It could be easily modified to find the "kBGD" chunk and then retrieve the data afterwards.