As suggested by Hans Passant, you can paint using what is currently on the canvas as an image for a texture brush (you may need double buffering to work correctly) and use ColorMatrix to change the colors painted on the canvas.
There is a color matrix that inverts colors similar to XOR, the problem is that it will not work with medium gray. A color matrix that inverts RGB and leaves alpha unchanged will be:
-1, 0, 0, 0, 0 0,-1, 0, 0, 0 0, 0,-1, 0, 0 0, 0, 0, 1, 0 1, 1, 1, 0, 1
Something similar, albeit slower, would be to copy the canvas onto the image and process that image pixel into a pixel with rules such as if the color were brighter than 0.5, make it a little darker, make it a little brighter. Then you draw the processed image as a texture. This will give a better result, but it will be significantly slower than using ColorMatrix .
Coincoin
source share