Opacity() method removing alpha from all pixels

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
User avatar
jonoomph
Posts: 27
Joined: 2011-03-27T14:25:09-07:00
Authentication code: 8675308

Opacity() method removing alpha from all pixels

Post by jonoomph » 2012-11-12T22:18:21-07:00

Using the C++ api, it seems like the opacity() method applies the same alpha value to all pixels in the image. If I use a completely opaque image, I can fade the entire image correctly. However, if the source image already contains alpha, such as a alpha gradient, or transparent corners, etc... the opacity() method seems to replace the alpha values... and thus removes the original transparency from the source image.

What is the best way to increase (or decrease) the existing alpha values in an image... without replacing them all with a single value?

For example, in the popular vector graphics app Inkscape, if you have a rectangle which contains an alpha gradient... you can still apply an opacity to the entire shape, which preservers the alpha gradient... it just increases the alpha or decreases the alpha values in the shape.

Thanks!
-Jonathan

User avatar
jonoomph
Posts: 27
Joined: 2011-03-27T14:25:09-07:00
Authentication code: 8675308

Re: Opacity() method removing alpha from all pixels

Post by jonoomph » 2012-11-12T23:14:29-07:00

I found that the quantumOperator(Magick::OpacityChannel, Magick::MultiplyEvaluateOperator, alpha_value) method seems to do the trick, and simply multiplies the new alpha percentage to all values in the alpha channel, and works great.

Thanks!
-Jonathan

Post Reply