RadialGradientBrush Class
A gradient around a point: the color is constant on circles around that point.
public sealed class RadialGradientBrush : GradientBrushRemarks
The parameter of a position is its distance to RadialGradientBrush.Center divided by RadialGradientBrush.Radius. When the radius is zero, the whole canvas has the color of the last stop.
With a RadialGradientBrush.FocalPoint that is not the center, the gradient spreads from the focal point to the circle of RadialGradientBrush.Center and RadialGradientBrush.Radius: the parameter of a position is how far it is from the focal point, as a fraction of the distance from the focal point to that circle in the same direction. The circle of a parameter t is centered t of the way from the focal point to the center, with a radius of t times RadialGradientBrush.Radius.
With a RadialGradientBrush.FocalRadius, the gradient starts on a circle around the focal point instead of at that point: the gradient between two circles of SVG 2 (fr) and of the HTML canvas. The circle of a parameter t is still centered t of the way from the focal point to the center, and its radius goes from RadialGradientBrush.FocalRadius to RadialGradientBrush.Radius. Inside the circle of the focal point, the parameter is negative: the color is the one of the first stop with GradientSpreadMode.Pad, and the gradient goes on toward the point where its circles shrink to nothing with the other spread modes.
The two circles can be anywhere, as for createRadialGradient of the HTML canvas: the circles of the parameters t (all of them, not only those from 0 to 1) whose radius r(t) is not negative form a cone, and a position has the largest t whose circle goes through it. A position that no such circle goes through (outside the cone) has no color: nothing is painted there, whatever the spread mode. When the first circle is inside the second one, every position has a parameter, and this is the gradient described above. Two circles of the same center and the same radius make no cone: with GradientSpreadMode.Pad, the inside of the circle has the color of the first stop and the rest of the canvas the color of the last one; with the other spread modes, nothing is painted.
With a RadialGradientBrush.RadiusY that is not RadialGradientBrush.Radius, the color is constant on ellipses instead: the circles above are stretched along y around RadialGradientBrush.Center by RadiusY / Radius, before GradientBrush.Transform, which can still turn them. This is the radial gradient with a GradientBrush.Transform that scales y around the center, written with the half-axes of the ellipse.
- Inheritance
GradientBrushRadialGradientBrush
Constructors
| Name | Description |
|---|---|
| RadialGradientBrush(PointD, double, double, ReadOnlySpan<GradientStop>) | Initializes a new instance of the RadialGradientBrush class whose color is constant on ellipses around a point. |
| RadialGradientBrush(PointD, double, ReadOnlySpan<GradientStop>) | Initializes a new instance of the RadialGradientBrush class. |
RadialGradientBrush overloads
RadialGradientBrush(PointD, double, double, ReadOnlySpan<GradientStop>)
RadialGradientBrush.csInitializes a new instance of the RadialGradientBrush class whose color is constant on ellipses around a point.
public RadialGradientBrush(PointD center, double radiusX, double radiusY, ReadOnlySpan<GradientStop> stops)Parameters
centerPointD- The position of offset 0, in canvas coordinates.
radiusXdouble- The half-axis along x of the ellipse of offset 1. Must be zero or positive.
radiusYdouble- The half-axis along y of the ellipse of offset 1. Must be zero or positive.
stopsReadOnlySpan<GradientStop>- The stops, in increasing order of offset. They are copied.
Exceptions
ArgumentException- There is no stop, the offsets decrease, or a coordinate or a half-axis is not a finite number.
ArgumentOutOfRangeException- The magnitude of a coordinate exceeds 16777216, or a half-axis is negative or exceeds 16777216.
Remarks
The gradient is the circular gradient of radius radiusX, stretched along y around center by radiusY / radiusX, before GradientBrush.Transform: the parameter of a position p is sqrt(dx^2 + (dy radiusX / radiusY)^2) / radiusX, with (dx, dy) = p - center. When one of the half-axes is zero and the other is not, the whole canvas has the color of the last stop.
RadialGradientBrush(PointD, double, ReadOnlySpan<GradientStop>)
RadialGradientBrush.csInitializes a new instance of the RadialGradientBrush class.
public RadialGradientBrush(PointD center, double radius, ReadOnlySpan<GradientStop> stops)Parameters
centerPointD- The position of offset 0, in canvas coordinates.
radiusdouble- The distance from the center at which the offset is 1. Must be zero or positive.
stopsReadOnlySpan<GradientStop>- The stops, in increasing order of offset. They are copied.
Exceptions
ArgumentException- There is no stop, the offsets decrease, or a coordinate or the radius is not a finite number.
ArgumentOutOfRangeException- The magnitude of a coordinate exceeds 16777216, or the radius is negative or exceeds 16777216.
Properties
| Name | Description |
|---|---|
| Center | Gets the center of the circle of offset 1; the position of offset 0 unless there is a RadialGradientBrush.FocalPoint. |
| FocalPoint | Gets the position of offset 0: the point the gradient spreads from, or the center of the circle it starts on. Defaults to RadialGradientBrush.Center. |
| FocalRadius | Gets the radius of the circle of offset 0, around RadialGradientBrush.FocalPoint: the gradient starts on that circle. Defaults to 0: the gradient starts at the focal point. |
| Radius | Gets the distance from the center at which the offset is 1: the radius of the circle of offset 1, or the half-axis along x of its ellipse. |
| RadiusY | Gets the half-axis along y of the ellipse of offset 1: RadialGradientBrush.Radius for a circular gradient. |
Center
RadialGradientBrush.csGets the center of the circle of offset 1; the position of offset 0 unless there is a RadialGradientBrush.FocalPoint.
public PointD Center { get; }Property value
FocalPoint
RadialGradientBrush.csGets the position of offset 0: the point the gradient spreads from, or the center of the circle it starts on. Defaults to RadialGradientBrush.Center.
public PointD FocalPoint { get; init; }Property value
Exceptions
ArgumentException- A coordinate is not a finite number.
ArgumentOutOfRangeException- The magnitude of a coordinate exceeds 16777216.
FocalRadius
RadialGradientBrush.csGets the radius of the circle of offset 0, around RadialGradientBrush.FocalPoint: the gradient starts on that circle. Defaults to 0: the gradient starts at the focal point.
public double FocalRadius { get; init; }Property value
Exceptions
ArgumentException- The value is not a finite number.
ArgumentOutOfRangeException- The value is negative or exceeds 16777216.
Radius
RadialGradientBrush.csRadiusY
RadialGradientBrush.csGets the half-axis along y of the ellipse of offset 1: RadialGradientBrush.Radius for a circular gradient.
public double RadiusY { get; }Property value
Remarks
When it differs from RadialGradientBrush.Radius, every circle of the gradient is stretched along y around RadialGradientBrush.Center by RadiusY / Radius: RadialGradientBrush.FocalPoint is the position of offset 0 after that stretch, and RadialGradientBrush.FocalRadius the half-axis along x of the ellipse of offset 0.