Using a DrawingBrush with a PathGeometry as an OpacityMask does not work as intended

809 views Asked by At

I'm trying to get a path to act as the OpacityMask for another path in order to draw just the outline. I've gotten two paths to overlap correctly, but when I create a GeometryDrawing from the PathGeometry, it produces some odd results that I can't understand.

To give you some idea of what I'm talking about, the following image is of two paths, one orange and one black, overlapping to produce the effect of an orange path with a black outline:

http://i.imgur.com/t0k3KvE.png

What I'm looking for is to make the orange path (the top one) the OpacityMask of the black one in order to create a transparency. When I attempt to create a GeometryDrawing to use with a DrawingBrush I get a strange effect:

http://i.imgur.com/wShmWxF.png

As you can see, instead of digging out the inside of the black path, it creates a mask around the outside of it, as well as distorting the actual data points on the path.

Here is the code that draws the first image:

path2 = new System.Windows.Shapes.Path();
path2.Data = path1.Data.Clone();
path2.StrokeThickness = path1.StrokeThickness / 1.5;

path1.Stroke = Brushes.Black;
path2.Stroke = Brushes.Orange;

manipulationCanvas.Children.Add(path1);
manipulationCanvas.Children.Add(path2);

Now barring the setup code and adding them to the canvas, the second image is created using the following code:

DrawingBrush opacityBrush = new DrawingBrush();
GeometryDrawing gDrawing = new GeometryDrawing(null, new Pen(Brushes.Black, path2.StrokeThickness), path1.Data);
opacityBrush.Drawing = gDrawing;

path1.Stroke = Brushes.Black;
path1.OpacityMask = opacityBrush;

path2.Stroke = Brushes.Orange;
path2.Opacity = 0.5;

Can anyone tell me why this is happening?

UPDATE 1: I've narrowed down the issue to being unable to carve out shapes from another element. From my understanding of opacity mask I was under the impression that providing the system with black and white colors allowed me to mask out certain areas of an image or control, but unfortunately what I get is the reverse: everything that is not transparent gets masked in.

0

There are 0 answers