Share via


方法 : 描画をクリップする

更新 : 2007 年 11 月

この例では、Drawing にクリップ領域を定義する方法を示します。

Drawing にクリップを定義するには、DrawingGroup を使用します。DrawingGroup クラスは、ユーザー独自のクリップ領域を定義できる Drawing オブジェクトの唯一の型です。

クリップを記述し、それを DrawingGroup オブジェクトの ClipGeometry プロパティに適用するには、Geometry を使用します。

使用例

楕円クリップを適用する前と後の DrawingGroup を示しています。

クリップ領域が定義された DrawingGroup

次のサンプルでは、DrawingGroup を使用して、複数の GeometryDrawing オブジェクトに ClipGeometry を適用しています。

<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>

参照

概念

Drawing オブジェクトの概要

ジオメトリの概要

参照

Geometry

Freeze

PresentationOptions:Freeze 属性