Change alpha blending mode in WPF?

The System.Drawing.Graphics class has a CompositionMode property with two parameters: SourceOver (which, based on the alpha component, mixes everything that is drawn with an existing background) or SourceCopy, which simply overwrites the background with what is drawn.

Is there something similar in WPF?

In WPF, when I draw PolyLine, for example, on top of another, the new PolyLine always has an alphabet with a background. I think this is independent of the container used. I am using Canvas but cannot find the blend mode property anywhere. What I want to do is what the SourceCopy method mentioned above mentions. That is, the new PolyLine should simply overwrite everything that is already on the canvas.

Is there an easy way to do this if you do not use pixel shaders (which, as I understand it) will not work, because I do not have access to the Canvas buffer form.

I am not stuck in Canvas and would be happy to use any container that supports rewriting mode.

I currently have a WriteableBitmap based solution for which I get the System.Drawing.Graphics context and then manipulate the CompositionMode. It works, but since my window is fullscreen, this solution has serious performance implications.

Explanation and example: The WPF window is completely transparent, as well as the Canvas (back color (0,0,0,0)). Now I draw PolyLine with Color.FromArgb (128,128,0,0). Now I have a translucent red polyline. Then I draw the same PolyLine with Color.FromArgb (0,0,0,0). The result is the same as before, due to the ongoing alpha blending. However, I want the red polyline to be erased using the second polyline (this is exactly what SourceCopy mode does in the Graphics class.

+6
wpf alphablending
source share
2 answers

I think all you have to do is make sure that the brushes used to fill / stroke the PolyLine have completely opaque alpha values ​​(i.e. 255 ). Then the background should not mix with it.

0
source share

You can apply a clipping mask, so you can provide a click path above the elements below it, but it can be difficult to maintain after a lot of elements are required to crop ...

0
source share

All Articles