FillRule失败时如何填充重叠区域?

时间:2009-11-12 07:30:13

标签: wpf xaml

我正在尝试绘制手工制作的DB鼓形状。问题是顶部椭圆没有完全填满。 样品:

<Page
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Grid>  
        <Image Width="126" Height="42" Margin="3" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Image.Source>
                <DrawingImage>
                    <DrawingImage.Drawing>
                        <GeometryDrawing Brush="Silver">
                            <GeometryDrawing.Pen>
                                <Pen Brush="Black" Thickness="1" LineJoin="Bevel" EndLineCap="Round" StartLineCap="Round" />
                            </GeometryDrawing.Pen>
                            <GeometryDrawing.Geometry>
                                <GeometryGroup FillRule="NonZero">
                                    <EllipseGeometry Center="62,8" RadiusX="62" RadiusY="5" />
                                    <PathGeometry>
                                        <PathFigure StartPoint="0,8" IsClosed="False">
                                            <LineSegment Point="0,38" />
                                            <QuadraticBezierSegment Point1="60,49" Point2="124,38" />
                                            <LineSegment Point="124,8" />
                                        </PathFigure>
                                    </PathGeometry>
                                </GeometryGroup>
                            </GeometryDrawing.Geometry>
                        </GeometryDrawing>
                    </DrawingImage.Drawing>
                </DrawingImage>
            </Image.Source>
        </Image>

  </Grid>
</Page>

解决此问题的任何替代方案? 感谢。

1 个答案:

答案 0 :(得分:0)

最后......解决方案是使用弧段制作两个单独的路径图:

<Page  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
    <Image Width="126" Height="42" Margin="3" HorizontalAlignment="Left" VerticalAlignment="Top">
        <Image.Source>
            <DrawingImage>
                <DrawingImage.Drawing>
                    <GeometryDrawing Brush="Silver">
                        <GeometryDrawing.Pen>
                            <Pen Brush="Black" Thickness="1" LineJoin="Bevel" EndLineCap="Round" StartLineCap="Round" />
                        </GeometryDrawing.Pen>
                        <GeometryDrawing.Geometry>
                            <GeometryGroup x:Key="Drum" FillRule="NonZero">
                                <PathGeometry>
                                    <PathFigure StartPoint="0,6" IsClosed="True">
                                        <ArcSegment Point="125,6" IsLargeArc="False" IsStroked="True" SweepDirection="Clockwise" Size="15,1.5" />
                                        <ArcSegment Point="0,6" IsLargeArc="False" IsStroked="True" SweepDirection="Clockwise" Size="15,1.5" />
                                    </PathFigure>
                                </PathGeometry>
                                <PathGeometry>
                                    <PathFigure StartPoint="0,6" IsClosed="True">
                                        <ArcSegment Point="125,6" IsLargeArc="False" IsStroked="True" Size="15,1.5" IsSmoothJoin="True" />
                                        <LineSegment Point="125,35" IsSmoothJoin="True" />
                                        <ArcSegment Point="0,35" IsLargeArc="False" IsStroked="True" SweepDirection="Clockwise" Size="15,1.5" IsSmoothJoin="True" />
                                        <LineSegment Point="0,6" IsSmoothJoin="True" />
                                    </PathFigure>
                                </PathGeometry>
                            </GeometryGroup>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingImage.Drawing>
            </DrawingImage>
        </Image.Source>
    </Image>  
</Grid>
</Page>