As Hans Passant proposed, you could paint using what's currently in the canvas as the image for a texture brush (you might need double buffering for that to work correctly) and use a ColorMatrix
to modify the colors being painted on the canvas.
There is a color matrix that inverts the colors similar to a XOR, the problem is it won't work with the middle gray. A color matrix that inverts RGB and leaves alpha intact would 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 to an image and process that image pixel per pixel with rules such as if the color is brighter than 0.5, make it slightly darker else, make it slightly brighter. Then, you paint with that processed image as a texture brush. This would give a better result but it would be significantly slower than using a ColorMatrix
.