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:
I would like to produce this image where the RGB channels are unchanged:
Note that there are a range of alpha values in the original and final images.