如何:对绘图进行剪辑
更新:2007 年 11 月
此示例演示如何为 Drawing 定义剪辑区域。
使用 DrawingGroup 可以为 Drawing 定义剪辑。您只能通过 DrawingGroup 类这个 Drawing 对象类型来定义自己的剪辑区域。
使用 Geometry 可描述该剪辑并将其应用于 DrawingGroup 对象的 ClipGeometry 属性。
示例
下面的插图显示在应用椭圆形剪辑之前和之后 DrawingGroup 的情况。
下面的示例使用 DrawingGroup 将 ClipGeometry 应用到若干个 GeometryDrawing 对象。
<Page
xmlns="https://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="https://schemas.microsoft.com/winfx/2006/xaml"
xmlns:PresentationOptions="https://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:mc="https://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="PresentationOptions"
Background="White" Margin="20">
<Border BorderBrush="Gray" BorderThickness="1"
HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="20">
<Image Stretch="None" HorizontalAlignment="Left">
<Image.Source>
<DrawingImage PresentationOptions:Freeze="True">
<DrawingImage.Drawing>
<!-- A DrawingGeometry with an elliptical clip region. -->
<DrawingGroup>
<GeometryDrawing Brush="Pink">
<GeometryDrawing.Geometry>
<RectangleGeometry Rect="0,0,50,85" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
<GeometryDrawing Brush="Lime"
Geometry="M 25,25 L 0,50 25,75 50,50 25,25 25,0">
<GeometryDrawing.Pen>
<Pen Thickness="10" Brush="Black" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<GeometryDrawing Brush="Lime">
<GeometryDrawing.Geometry>
<EllipseGeometry Center="10,10" RadiusX="5" RadiusY="5" />
</GeometryDrawing.Geometry>
<GeometryDrawing.Pen>
<Pen Thickness="2" Brush="Black" />
</GeometryDrawing.Pen>
</GeometryDrawing>
<DrawingGroup.ClipGeometry>
<EllipseGeometry Center="25,50" RadiusX="25" RadiusY="50" />
</DrawingGroup.ClipGeometry>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</Image.Source>
</Image>
</Border>
</Page>