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


C# PathGeometry.GetFlattenedPathGeometry方法代码示例

本文整理汇总了C#中System.Windows.Media.PathGeometry.GetFlattenedPathGeometry方法的典型用法代码示例。如果您正苦于以下问题:C# PathGeometry.GetFlattenedPathGeometry方法的具体用法?C# PathGeometry.GetFlattenedPathGeometry怎么用?C# PathGeometry.GetFlattenedPathGeometry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Media.PathGeometry的用法示例。


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

示例1: DrawFormattedText

        private void DrawFormattedText(DpiScaleInfo dpiInfo)
        {
            FormattedText formattedText = new FormattedText(
                "FABLE",
                new System.Globalization.CultureInfo("en-US"),
                FlowDirection.LeftToRight,
                new Typeface(
                    new System.Windows.Media.FontFamily("Segoe UI"),
                    FontStyles.Normal,
                    FontWeights.Bold,
                    FontStretches.Normal),
                120,
                System.Windows.Media.Brushes.Red,
                dpiInfo.PixelsPerDip);

            // Build a geometry out of the text.
            Geometry geometry = new PathGeometry();
            geometry = formattedText.BuildGeometry(new System.Windows.Point(0, 0));

            // Adjust the geometry to fit the aspect ration of the video by scaling it.
            ScaleTransform myScaleTransform = new ScaleTransform();
            myScaleTransform.ScaleX = .85;
            myScaleTransform.ScaleY = 2.0;
            geometry.Transform = myScaleTransform;

            // Flatten the geometry and create a PathGeometry out of it.
            PathGeometry pathGeometry = new PathGeometry();
            pathGeometry = geometry.GetFlattenedPathGeometry();

            // Use the PathGeometry for the empty placeholder Path element in XAML.
            path.Data = pathGeometry;

            // Use the PathGeometry for the animated ball that follows the path of the text outline.
            matrixAnimation.PathGeometry = pathGeometry;
        }
开发者ID:blinds52,项目名称:WPF-Samples,代码行数:35,代码来源:MainWindow.xaml.cs

示例2: ComputeLength

        public static double ComputeLength(PathGeometry path)
        {
            PathGeometry flattenedPath = path.GetFlattenedPathGeometry();
            double length = 0;
            Point prev = path.Figures[0].StartPoint;
            foreach (PolyLineSegment segment in flattenedPath.Figures[0].Segments)
            {
                foreach (Point p in segment.Points)
                {
                    double d = Point.Subtract(p, prev).Length;
                    prev = p;
                    length += d;
                }
            }

            return length;
        }
开发者ID:yong-ja,项目名称:starodyssey,代码行数:17,代码来源:Bezier.cs

示例3: FlattenSegment

 /// <summary>
 /// Converts a PolyQuadraticBezierSegment into a PolyLineSegment because I currently have no muse to calculate
 /// the correct Bézier curves.
 /// </summary>
 public static PdfSharp.Xps.XpsModel.PolyLineSegment FlattenSegment(PdfSharp.Xps.XpsModel.Point startPoint,
   PdfSharp.Xps.XpsModel.PolyQuadraticBezierSegment seg)
 {
   PathGeometry geo = new PathGeometry();
   PathFigure fig = new PathFigure();
   geo.Figures.Add(fig);
   fig.StartPoint = new Point(startPoint.X, startPoint.Y);
   int count = seg.Points.Count;
   Point[] points = new Point[count];
   for (int idx = 0; idx < count - 1; idx += 2)
   {
     QuadraticBezierSegment qbseg = new QuadraticBezierSegment(
       new Point(seg.Points[idx].X, seg.Points[idx].Y), new Point(seg.Points[idx + 1].X, seg.Points[idx + 1].Y), seg.IsStroked);
     fig.Segments.Add(qbseg);
   }
   geo = geo.GetFlattenedPathGeometry();
   fig = geo.Figures[0];
   PolyLineSegment lineSeg = (PolyLineSegment)fig.Segments[0];
   PdfSharp.Xps.XpsModel.PolyLineSegment resultSeg = new PdfSharp.Xps.XpsModel.PolyLineSegment();
   foreach (Point point in lineSeg.Points)
     resultSeg.Points.Add(new PdfSharp.Xps.XpsModel.Point(point.X, point.Y));
   return resultSeg;
 }
开发者ID:alexiej,项目名称:YATE,代码行数:27,代码来源:WpfUtils.cs

示例4: AppendPath

    /// <summary>
    /// Appends the content of a PathGeometry object.
    /// </summary>
    internal void AppendPath(PathGeometry geometry)
    {
#if true_
      // sissy version
      geometry = geometry.GetFlattenedPathGeometry();
#endif
      foreach (PathFigure figure in geometry.Figures)
      {
        System.Windows.Point currentPoint = new System.Windows.Point();

        // Move to start point
        currentPoint = figure.StartPoint;
        AppendFormat("{0:0.####} {1:0.####} m\n", currentPoint.X, currentPoint.Y);

        foreach (PathSegment segment in figure.Segments)
        {
          Type type = segment.GetType();
          if (type == typeof(LineSegment))
          {
            // Draw a single line
            System.Windows.Point point = ((LineSegment)segment).Point;
            currentPoint = point;
            AppendFormat("{0:0.####} {1:0.####} l\n", point.X, point.Y);
          }
          else if (type == typeof(PolyLineSegment))
          {
            // Draw connected lines
            PointCollection points = ((PolyLineSegment)segment).Points;
            foreach (System.Windows.Point point in points)
            {
              currentPoint = point; // I forced myself not to optimize this assignment
              AppendFormat("{0:0.####} {1:0.####} l\n", point.X, point.Y);
            }
          }
          else if (type == typeof(BezierSegment))
          {
            // Draw Bézier curve
            BezierSegment seg = (BezierSegment)segment;
            System.Windows.Point point1 = seg.Point1;
            System.Windows.Point point2 = seg.Point2;
            System.Windows.Point point3 = seg.Point3;
            AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
              point1.X, point1.Y, point2.X, point2.Y, point3.X, point3.Y);
            currentPoint = point3;
          }
          else if (type == typeof(PolyBezierSegment))
          {
            // Draw connected Bézier curves
            PointCollection points = ((PolyBezierSegment)segment).Points;
            int count = points.Count;
            if (count > 0)
            {
              Debug.Assert(count % 3 == 0, "Number of Points in PolyBezierSegment are not a multiple of 3.");
              for (int idx = 0; idx < count - 2; idx += 3)
              {
                System.Windows.Point point1 = points[idx];
                System.Windows.Point point2 = points[idx + 1];
                System.Windows.Point point3 = points[idx + 2];
                AppendFormat("{0:0.####} {1:0.####} {2:0.####} {3:0.####} {4:0.####} {5:0.####} c\n",
                  point1.X, point1.Y, point2.X, point2.Y, point3.X, point3.Y);
              }
              currentPoint = points[count - 1];
            }
          }
          else if (type == typeof(ArcSegment))
          {
            // Draw arc
            ArcSegment seg = (ArcSegment)segment;
            AppendPartialArc(currentPoint, seg.Point, seg.RotationAngle, seg.Size, seg.IsLargeArc, seg.SweepDirection, PathStart.Ignore1st);
            currentPoint = seg.Point;
          }
          else if (type == typeof(QuadraticBezierSegment))
          {
            QuadraticBezierSegment seg = (QuadraticBezierSegment)segment;
            currentPoint = seg.Point2;
            // TODOWPF: Undone because XGraphics has no such curve type
            throw new NotImplementedException("AppendPath with QuadraticBezierSegment.");
          }
          else if (type == typeof(PolyQuadraticBezierSegment))
          {
            PolyQuadraticBezierSegment seg = (PolyQuadraticBezierSegment)segment;
            currentPoint = seg.Points[seg.Points.Count - 1];
            // TODOWPF: Undone because XGraphics has no such curve type
            throw new NotImplementedException("AppendPath with PolyQuadraticBezierSegment.");
          }
        }
        if (figure.IsClosed)
          Append("h\n");
      }
    }
开发者ID:zheimer,项目名称:PDFSharp,代码行数:93,代码来源:XGraphicsPdfRenderer.cs

示例5: GetFlattenedPathFigure

        /// <summary>
        /// Approximate this figure with a polygonal PathFigure
        /// </summary>
        /// <param name="tolerance">The approximation error tolerance</param>
        /// <param name="type">The way the error tolerance will be interpreted - relative or absolute</param>
        /// <returns>Returns the polygonal approximation as a PathFigure.</returns>
        public PathFigure GetFlattenedPathFigure(double tolerance, ToleranceType type)
        {
            PathGeometry geometry = new PathGeometry();
            geometry.Figures.Add(this);

            PathGeometry flattenedGeometry = geometry.GetFlattenedPathGeometry(tolerance, type);

            int count = flattenedGeometry.Figures.Count;

            if (count == 0)
            {
                return new PathFigure();
            }
            else if (count == 1)
            {
                return flattenedGeometry.Figures[0];
            }
            else
            {
                throw new InvalidOperationException(SR.Get(SRID.PathGeometry_InternalReadBackError));
            }
        }
开发者ID:JianwenSun,项目名称:cc,代码行数:28,代码来源:PathFigure.cs


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