Quantcast
Channel: Invert alpha value of a canvas image - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Invert alpha value of a canvas image

$
0
0

What is the best way to invert the alpha channel of a canvas' content?

I have seen solutions such as this one where you can go through pixel-by-pixel and re-map the alpha value, but this is an expensive operation, and I was hoping that there might be something more performant (or better practice) method, such as a way of using context.filter or something similar to do this.

As a simplified example, given this image, where all pixels have the same RGB channel (black) values but varying alpha channel values:

enter image description here

I would like to produce this image where the RGB channels are unchanged:

enter image description here

Note that there are a range of alpha values in the original and final images.


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images