[Gdal-dev] Transparent PNG with color table (palette)

Frank Warmerdam warmerdam at pobox.com
Mon May 28 08:38:01 EDT 2007


Ludwig M Brinckmann wrote:
> I need to create paletted PNG files with transparency.
> 
> I understand that I need to pass in a colour table with the alpha 
> channel set to 0.
> 
> As I cannot create PNGs directly, I first create a Tiff with the 
> colourtable and then do a CreateCopy.
> 
> But when I then look at the PNG colour table, the transparency values 
> are gone (all set to 255). This is also true for the intermediate Tiff 
> file -- which is understandable as single band tiffs don't do 
> transparency. I think when creating the tiff the colourtable is adjusted 
> so that it works for the Tiff, but then my transparencies are lost. (If 
> someone thinks this is a bug, I will turn my code into a short example).
> 
> I tried to alter the colour table after creating the tiff (or the 
> createCopy of the PNG), but this is not supported.
> 
> What's the best way to do this -- maybe I just need a better 
> intermediate format that does transparencies and can be created (which 
> one?)

Ludwig,

If you image isn't too large, and you are doing programatically (or
via scripts) you might want to use MEM format as your intermediate format.
I believe it supports fully featured color tables, and no mess and fuss
with intermediate file cleanup.

   http://www.gdal.org/frmt_mem.html

Note, when creating MEM datasets and not needing to attach to an existing
array in memory, just use any name for the dataset, such as "tempimage".

Best regards,
-- 
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up   | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush    | President OSGeo, http://osgeo.org




More information about the Gdal-dev mailing list