How to set transparent colour in Magick++

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Malvineous
Posts: 5
Joined: 2010-07-10T21:25:42-07:00
Authentication code: 8675308

How to set transparent colour in Magick++

Post by Malvineous »

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:

Code: Select all

Magick::ColorRGB x(1, 0, 0);
x.alpha(1.0);
Magick::Image png;
...
png.colorMap(16, x);
That just treats the colour normally, no transparency.

Code: Select all

png.matte(true);
png.matteColor(x);
Has no effect.

Code: Select all

png.transparent(x);
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:

Code: Select all

Magick::Color asdf("transparent");
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.
Post Reply