在两个独立形状对象的相交处绘制不同的画笔

发布于 2024-08-02 02:52:28 字数 47 浏览 4 评论 0原文

当两个形状对象相互重叠时,WPF 中是否有办法使对象的重叠部分用不同的画笔绘制?

Is there a way in WPF when two shape objects overlap each other that the overlapping portions of the object get painted in a different brush?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凡间太子 2024-08-09 02:52:28

解决了。

您可以使用包含填充规则为 EvenOdd 的 GeometryGroup 的几何图形。 这会将任何重叠的项目涂成白色。 然后,只需将另一个图像放在组合几何的顶部,其中包含与几何组相同的对象,且几何组合模式为相交,这将突出显示自定义画笔中的相交。 示例代码如下:

    <Grid>
    <Image Stretch="None">
        <Image.Source>
            <DrawingImage>
                <DrawingImage.Drawing>
                    <GeometryDrawing Brush="Red">
                        <GeometryDrawing.Pen>
                            <Pen Brush="Black" Thickness="3" />
                        </GeometryDrawing.Pen>
                        <GeometryDrawing.Geometry>
                            <GeometryGroup FillRule="EvenOdd">
                                <EllipseGeometry RadiusX="80" RadiusY="80" Center="0,0" />
                                <EllipseGeometry RadiusX="80" RadiusY="80" Center="40,0" />
                            </GeometryGroup>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingImage.Drawing>
            </DrawingImage>
        </Image.Source>
    </Image>
    <Image HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stretch="None">
        <Image.Source>
            <DrawingImage>
                <DrawingImage.Drawing>
                    <GeometryDrawing Brush="LightBlue">
                        <GeometryDrawing.Geometry>
                            <CombinedGeometry GeometryCombineMode="Intersect">
                                <CombinedGeometry.Geometry1>
                                    <EllipseGeometry RadiusX="80" RadiusY="80" Center="0,0" />
                                </CombinedGeometry.Geometry1>
                                <CombinedGeometry.Geometry2>
                                    <EllipseGeometry RadiusX="80" RadiusY="80" Center="40,0" />
                                </CombinedGeometry.Geometry2>
                            </CombinedGeometry>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingImage.Drawing>
            </DrawingImage>
        </Image.Source>
    </Image>
</Grid>

谢谢!

Worked it out.

You can use a geometry drawing containing a GeometryGroup with a fill rule of EvenOdd. This paints any overlapping items in white. Then just put another image over the top with CombinedGeometry containing the same objects as the Geometry group with a GeometryCombineMode of Intersect and that will highlight the intersect in your custom brush. The sample code is below:

    <Grid>
    <Image Stretch="None">
        <Image.Source>
            <DrawingImage>
                <DrawingImage.Drawing>
                    <GeometryDrawing Brush="Red">
                        <GeometryDrawing.Pen>
                            <Pen Brush="Black" Thickness="3" />
                        </GeometryDrawing.Pen>
                        <GeometryDrawing.Geometry>
                            <GeometryGroup FillRule="EvenOdd">
                                <EllipseGeometry RadiusX="80" RadiusY="80" Center="0,0" />
                                <EllipseGeometry RadiusX="80" RadiusY="80" Center="40,0" />
                            </GeometryGroup>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingImage.Drawing>
            </DrawingImage>
        </Image.Source>
    </Image>
    <Image HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Stretch="None">
        <Image.Source>
            <DrawingImage>
                <DrawingImage.Drawing>
                    <GeometryDrawing Brush="LightBlue">
                        <GeometryDrawing.Geometry>
                            <CombinedGeometry GeometryCombineMode="Intersect">
                                <CombinedGeometry.Geometry1>
                                    <EllipseGeometry RadiusX="80" RadiusY="80" Center="0,0" />
                                </CombinedGeometry.Geometry1>
                                <CombinedGeometry.Geometry2>
                                    <EllipseGeometry RadiusX="80" RadiusY="80" Center="40,0" />
                                </CombinedGeometry.Geometry2>
                            </CombinedGeometry>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingImage.Drawing>
            </DrawingImage>
        </Image.Source>
    </Image>
</Grid>

Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文