0

我对齐了两张图像,一张在另一张上,

我正在尝试在顶部设置一个透明圆圈

出于某种原因,EllipseGeometry Radius 和 Center 属性不起作用。

这是 XAML 代码

谢谢 !

    <Viewbox Grid.Row="1" Stretch="Uniform" HorizontalAlignment="Center">
        <Image Name="BackImage" Width="640" Height="480" Source="Images/black.png"/>

    </Viewbox>
    <Viewbox Grid.Row="1" Stretch="Uniform" HorizontalAlignment="Center">
        <Image Name="FrontImage" Width="640" Height="480" Source="Images/white.png">
            <Image.OpacityMask>
                <DrawingBrush>
                    <DrawingBrush.Drawing>
                            <GeometryDrawing>
                                <GeometryDrawing.Pen>
                                    <Pen Thickness="0" Brush="Transparent" />
                                </GeometryDrawing.Pen>
                                <GeometryDrawing.Brush>
                                    <SolidColorBrush Color="Black" />
                                </GeometryDrawing.Brush>
                                <GeometryDrawing.Geometry>
                                        <EllipseGeometry Center="0,0" RadiusX="1" RadiusY="3"/>
                                </GeometryDrawing.Geometry>
                            </GeometryDrawing>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </Image.OpacityMask>
        </Image>

    </Viewbox>

这是我试图实现的目标.

4

1 回答 1

3

为了在绝对坐标中指定 GeometryDrawing,您必须将StretchDrawingBrush 的属性设置为None

此外,我还建议将两个图像放在一个 ViewBox 中。

<Viewbox Stretch="Uniform" HorizontalAlignment="Center">
    <Grid>
        <Image Name="BackImage" Width="640" Height="480" Source="Images/black.png"/>
        <Image Name="FrontImage" Width="640" Height="480" Source="Images/white.png">
            <Image.OpacityMask>
                <DrawingBrush Stretch="None">
                    <DrawingBrush.Drawing>
                        <GeometryDrawing Brush="Black">
                            <GeometryDrawing.Geometry>
                                <EllipseGeometry Center="320,240"
                                                 RadiusX="150" RadiusY="100"/>
                            </GeometryDrawing.Geometry>
                        </GeometryDrawing>
                    </DrawingBrush.Drawing>
                </DrawingBrush>
            </Image.OpacityMask>
        </Image>
    </Grid>
</Viewbox>
于 2013-08-15T05:32:29.147 回答