Core C API - Manipulating Alpha Channnel
Posted: 2014-05-01T18:48:33-07:00
I've got my monochrome TIFF in memory and want to add an alpha channel and then apply the correct alpha values via TransparentPaintImage.
But I either end up with no alpha (bitonal image again - does ImageMagick optimize on output ?) Or a completely transparent on every pixel image.
Currently, I'm trying this:
What I end up with is my image, in 32 bit color space, but all of the pixels are transparent. With a black and white image (colors 0 or 1) I'd expect that either all the white or all the black pixels were transparent.
Changing my opacity value to 0 has no effect - same image, 100% transparent pixels.
Does TransparentPaintImage work as expected?
But I either end up with no alpha (bitonal image again - does ImageMagick optimize on output ?) Or a completely transparent on every pixel image.
Currently, I'm trying this:
Code: Select all
TransformImageColorspace(imgMagickImage, RGBColorspace);
imgMagickImage->matte= MagickTrue; // force an alpha channel
// set the transparency (alpha channel on the image)
SetImageAlphaChannel( imgMagickImage, AlphaChannelType::ActivateAlphaChannel);
//SetImageAlphaChannel( imgMagickImage, AlphaChannelType::OpaqueAlphaChannel); // set an opaque alpha channel
MagickPixelPacket imgFilter; // determines which pixels are set to transparent
imgFilter.red=0;
imgFilter.green=0;
imgFilter.blue=0;
imgFilter.fuzz = 0; // anything near white is also transparent
Quantum opacity = QuantumRange; // quantum range is 0 to QuantumRange (eg 65535)
MagickBooleanType invertBool = MagickFalse; //
TransparentPaintImage( imgMagickImage, &imgFilter, opacity, invertBool);
Changing my opacity value to 0 has no effect - same image, 100% transparent pixels.
Does TransparentPaintImage work as expected?