BBC BASIC for Windows
Programming >> Graphics and Games >> Saving transparent GIFs
http://bb4w.conforums.com/index.cgi?board=graphics&action=display&num=1381362475

Saving transparent GIFs
Post by JGHarston on Oct 9th, 2013, 11:47pm

The Wiki article Saving a GIF image gives code to save a GIF. Is it possible to specify a transparent colour in the saved GIF?

I've spent about an hour trawling through online GDIPlus documentation, and actually ended up back at the Wiki! I could do it by manually opening the saved file and adding a GIF extension block with the required data, so if the GDIPlus functions don't support it I'll write an updated library function to let you specify a transparency.

Re: Saving transparent GIFs
Post by admin on Oct 10th, 2013, 04:55am

on Oct 9th, 2013, 11:47pm, JGHarston wrote:
The Wiki article Saving a GIF image gives code to save a GIF. Is it possible to specify a transparent colour in the saved GIF?

I believe it to be quite straightforward. The Microsoft documentation states of GDI+ that "The GIF encoder identifies the first color in the ColorPalette that has an Alpha value of ZERO as the transparent color".

So it should be sufficient to modify your colour palette (either in the source BMP file or in memory) such that the desired transparent colour has an alpha value of zero and all the others have an alpha value of 255.

However I have not tried this myself and with Windows graphics you can never be sure things will work 'sensibly'! So if you have difficulties or you find it doesn't work ask here again.

Richard.