【问题标题】:Convert Ellipse or EllipseGeometry to PathFigure on Windows Phone 8.1在 Windows Phone 8.1 上将 Ellipse 或 EllipseGeometry 转换为 PathFigure
【发布时间】:2016-01-03 09:30:48
【问题描述】:

我偶然发现将 Ellipse 转换为 PathGeometry。 我尝试使用 ArcSegment 来呈现 Ellipse,但仍然不知道如何将 Ellipse 大小转换为 ArcSegment 大小。我试图将椭圆分成两部分,但还有其他方法,即贝塞尔曲线。 需要线索如何将 Ellipse 转换为 ArcSegment 集合。 整个过程可能是这样的:

public static PathFigure ToFigures(this Ellipse ellipse)
{
    var pathFigure = new PathFigure {IsClosed = true};
    var arcSegment1 = new ArcSegment();
    var arcSegment2 = new ArcSegment();
    pathFigure.Segments.Add(arcSegment1);
    pathFigure.Segments.Add(arcSegment2);
    return pathFigure;
}

【问题讨论】:

  • 您是否只是想将椭圆分割为弧段中的两个部分?或者甚至需要弧段,您可以只做一个 EllipseGeometry 或只是一个 Path 作为椭圆??
  • 椭圆分割成两部分就可以了。作为源对象,我可以选择 Ellipse 或 EllipseGeometry。对于输出,需要 PathGeometry 或 PathFigure。
  • 因此,如果您不想/不能徒手绘制几何图形,这是一种非常简单的方法。打开 Blend,根据自己的喜好在画板上放置一个椭圆,然后右键单击 -> 路径 -> 转换为路径。除了我仍然不确定您要做什么,因为您提到了源和输出。听起来您更像是在寻找转换器。
  • 我需要在代码中创建 PathGeometry 或 PathFigure,而不是在编辑器中。
  • 哥们,你的问题有点混乱。要将 Ellipse 转换为 PathGeometry 的第一句话。第二句您说您将 ArcSegment 呈现为椭圆。然后倒数第二句要将 Ellipse 转换为 ArcSegment 集合。你到底想做什么?您是否正在寻找可以将 Ellipse 转换为 Path,或 Ellipse 为 ArcSegment Collection,或 ArcSegment 为 Path 的转换器。你可能想重新措辞。

标签: c# xaml shape drawing2d winrt-component


【解决方案1】:

您可以直接使用 EllipseGeometry 作为路径数据:

path = new Path
{
    Data = new EllipseGeometry { RadiusX = 100, RadiusY = 50 }
};

使用椭圆的大小,它看起来像这样:

path = new Path
{
    Data = new EllipseGeometry
    {
        RadiusX = ellipse.ActualWidth / 2,
        RadiusY = ellipse.ActualHeight / 2
    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多