0

我正在查看 LinearGradientBrush 类的构造函数,我看到它有一个覆盖,它采用 GradientStops 的集合和一个 double 作为角度。

当我查看它的属性时,一旦定义了它,我就找不到如何从画笔中获得角度。

有没有办法做到这一点,或者我将不得不编写一些函数来查看起点和终点并从中计算角度?(Blech - 请不要告诉我这是我唯一的选择......)

4

1 回答 1

1

一旦定义了画笔,我就找不到如何从画笔中获得角度。

根据referencesource.microsoft.comangle不存储,而只是用于计算EndPoint

public LinearGradientBrush(GradientStopCollection gradientStopCollection,
                           double angle) : base (gradientStopCollection)
{
    EndPoint = EndPointFromAngle(angle);
}

private Point EndPointFromAngle(double angle)
{
     // Convert the angle from degrees to radians
     angle = angle * (1.0/180.0) * System.Math.PI;

     return (new Point(System.Math.Cos(angle), System.Math.Sin(angle)));            
}

angle从那里得到应该EndPoint是直截了当的。

于 2016-02-28T01:18:12.400 回答