当前位置: 首页>>代码示例>>C#>>正文


C# DrawingGroup.ClipGeometry属性代码示例

本文整理汇总了C#中System.Windows.Media.DrawingGroup.ClipGeometry属性的典型用法代码示例。如果您正苦于以下问题:C# DrawingGroup.ClipGeometry属性的具体用法?C# DrawingGroup.ClipGeometry怎么用?C# DrawingGroup.ClipGeometry使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。


在下文中一共展示了DrawingGroup.ClipGeometry属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ClipExample

//引入命名空间
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SDKSample
{
    /// <summary>
    /// Shows how to define a clip region for a DrawingGroup.
    /// </summary>
    public class ClipExample : Page
    {
        public ClipExample()
        {

            //
            // Create several GeometryDrawing objects.
            //

            // Create a rectangle.
            GeometryDrawing drawing1 = new GeometryDrawing(
                Brushes.Pink,
                null, 
                new RectangleGeometry(new Rect(0,0,50,85))
                );

            //
            // Create a polygon.
            //
            PathFigure pLineFigure = new PathFigure();
            pLineFigure.StartPoint = new Point(25, 25);
            PolyLineSegment pLineSegment = new PolyLineSegment();
            pLineSegment.Points.Add(new Point(0, 50));
            pLineSegment.Points.Add(new Point(25, 75));
            pLineSegment.Points.Add(new Point(50, 50));
            pLineSegment.Points.Add(new Point(25, 25));
            pLineSegment.Points.Add(new Point(25, 0));
            pLineFigure.Segments.Add(pLineSegment);
            PathGeometry pGeometry = new PathGeometry();
            pGeometry.Figures.Add(pLineFigure);

            GeometryDrawing drawing2 = new GeometryDrawing(
                    Brushes.Lime,
                    new Pen(Brushes.Black, 10),
                    pGeometry
                );

            //
            // Create a circle.
            //
            GeometryDrawing drawing3 = new GeometryDrawing(
                    Brushes.Lime,
                    new Pen(Brushes.Black, 2),
                    new EllipseGeometry(new Point(10, 10), 5, 5)
                );

            // Create the DrawingGroup and add the
            // geometry drawings.
            DrawingGroup aDrawingGroup = new DrawingGroup();
            aDrawingGroup.Children.Add(drawing1);
            aDrawingGroup.Children.Add(drawing2);
            aDrawingGroup.Children.Add(drawing3);

            //
            // Create an EllipseGeometry and use it to
            // clip the DrawingGroup.
            //
            EllipseGeometry clipGeometry = 
                new EllipseGeometry(new Point(25,50), 25, 50);
            aDrawingGroup.ClipGeometry = clipGeometry;

            // Use an Image control and a DrawingImage to
            // display the drawing.
            DrawingImage aDrawingImage = new DrawingImage(aDrawingGroup);

            // Freeze the DrawingImage for performance benefits.
            aDrawingImage.Freeze();

            Image anImage = new Image();
            anImage.Source = aDrawingImage;
            anImage.Stretch = Stretch.None;
            anImage.HorizontalAlignment = HorizontalAlignment.Left;

            // Create a border around the images and add it to the
            // page.
            Border imageBorder = new Border();
            imageBorder.BorderBrush = Brushes.Gray;
            imageBorder.BorderThickness = new Thickness(1);
            imageBorder.VerticalAlignment = VerticalAlignment.Top;
            imageBorder.HorizontalAlignment = HorizontalAlignment.Left;
            imageBorder.Margin = new Thickness(20);
            imageBorder.Child = anImage;

            this.Background = Brushes.White;
            this.Margin = new Thickness(20);
            this.Content = imageBorder;
        }
    }
}
开发者ID:.NET开发者,项目名称:System.Windows.Media,代码行数:102,代码来源:DrawingGroup.ClipGeometry


注:本文中的System.Windows.Media.DrawingGroup.ClipGeometry属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。