I have a PathGeometry defining some path like this one:
original path http://devblog.ailon.org/devblog/_stuff/wpfpathgeoquestion/original.gif
This is a simplified example. In reality it can have segments of any type (Line, Arc, Bezier).
Now I need to cut a hole of some sort and size (square, circle, etc.) in segment joint points so the final result looks something like this:
with holes http://devblog.ailon.org/devblog/_stuff/wpfpathgeoquestion/with_holes.gif
My initial idea was to combine the original PathGeometry with other Geometry containing squares (or whatever) in the joint points using GeometryCombineMode.Exclude. Unfortunately this produces empty geometry if path is not filled. And if it is filled it produces incorrect result.
So I'm stuck. In simple example with line segments I could've calculated the border points upfront and made my line segments end there, but with arcs and beziers this would be sort of overkill.
Does anyone have an idea how to accomplish this?
Note: I need these holes erased (transparent) so placing a white square above it wont do.
Oh. Did it. The idea is to create an OpacityMask out of your holes using DrawingBrush and then push it on the drawing context before drawing the PathGeometry. Something like this.
RectangleGeometry r = new RectangleGeometry(graphVisual.Bounds);
GeometryDrawing dr = new GeometryDrawing(Brushes.Black, null, Geometry.Combine(r, bulletHoles, GeometryCombineMode.Exclude, null));
DrawingBrush br = new DrawingBrush(dr);
drawingContext.PushOpacityMask(br);
drawingContext.DrawGeometry(null, new Pen(Brushes.Green, 2), graphVisual);
drawingContext.Pop();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With