How to set transparent colour in Magick++
Posted: 2010-07-10T21:34:56-07:00
Hi all,
I'm trying to produce a 16-colour indexed/palette/PseudoColor PNG image with transparency. I would like an alpha channel but it doesn't look like this is possible, so I can settle for assigning one of the colours in the palette as transparent (although this means my 16-colour image will become an unusual 17-colours.)
Unfortunately I can't figure out how this should work. I'm using the Magick++ library, and none of these work:
That just treats the colour normally, no transparency.
Has no effect.
This causes a segfault if called before the pixels have been set, and if called after it has no effect.
I can't see any other way to assign transparency for an indexed image, so any pointers would be much appreciated!
EDIT: I'm really struggling to understand the logic here - it looks like there are some fairly major bugs in the library, for example this:
Causes most of my image to be replaced with the last colour in the colourmap (which becomes transparent) even though that variable is never used! I can call it whatever I want, it doesn't matter. If I comment out the line then the image returns to normal (all pixels visible again) and no colours are set to transparent. That's some pretty serious side effects there...
EDIT2: Never mind, I switched to libpng++ and it works like a dream! I guess ImageMagick is more aimed at image manipulation rather than plain reading and writing of image files.
I'm trying to produce a 16-colour indexed/palette/PseudoColor PNG image with transparency. I would like an alpha channel but it doesn't look like this is possible, so I can settle for assigning one of the colours in the palette as transparent (although this means my 16-colour image will become an unusual 17-colours.)
Unfortunately I can't figure out how this should work. I'm using the Magick++ library, and none of these work:
Code: Select all
Magick::ColorRGB x(1, 0, 0);
x.alpha(1.0);
Magick::Image png;
...
png.colorMap(16, x);
Code: Select all
png.matte(true);
png.matteColor(x);
Code: Select all
png.transparent(x);
I can't see any other way to assign transparency for an indexed image, so any pointers would be much appreciated!
EDIT: I'm really struggling to understand the logic here - it looks like there are some fairly major bugs in the library, for example this:
Code: Select all
Magick::Color asdf("transparent");
EDIT2: Never mind, I switched to libpng++ and it works like a dream! I guess ImageMagick is more aimed at image manipulation rather than plain reading and writing of image files.