Class LinearGradient
public sealed record LinearGradient : Gradient, ITextPaint, IEquatable<Paint>, IEquatable<Gradient>, IEquatable<LinearGradient>
- Inheritance
-
LinearGradient
- Implements
- Inherited Members
Examples
using (RasterCanvas<Rgba8> canvas = raster.CreateCanvas())
{
// Two colors along a line; past the ends the end colors repeat (TileMode.Clamp).
canvas.FillRect(new RectF(0, 0, 200, 100), new LinearGradient(new Vector2(0, 0), new Vector2(200, 0), new RgbaF32(0.1f, 0.3f, 0.9f, 1), new RgbaF32(1, 0.8f, 0.2f, 1)));
// Several stops, mixed in Oklab for even midpoints, repeating every 40 pixels.
canvas.FillRect(new RectF(200, 0, 200, 100), new LinearGradient(
new Vector2(200, 0),
new Vector2(240, 0),
new GradientStop(0, new Rgba8(230, 40, 60, 255)),
new GradientStop(0.5f, new Rgba8(250, 210, 60, 255)),
new GradientStop(1, new Rgba8(230, 40, 60, 255)))
{
Tile = TileMode.Repeat,
Interpolation = GradientInterpolation.Oklab,
});
// A radial gradient stretched into an ellipse by its local matrix, and a sweep around a center.
canvas.FillOval(new RectF(10, 110, 180, 80), new RadialGradient(Vector2.Zero, 1, new RgbaF32(1, 1, 1, 1), new RgbaF32(0, 0.4f, 0.2f, 1))
{
LocalMatrix = Matrix3x2.CreateScale(90, 40) * Matrix3x2.CreateTranslation(100, 150),
});
canvas.FillCircle(new Vector2(300, 150), 45, new SweepGradient(
new Vector2(300, 150),
new GradientStop(0, new Rgba8(255, 0, 0, 255)),
new GradientStop(0.5f, new Rgba8(0, 0, 255, 255)),
new GradientStop(1, new Rgba8(255, 0, 0, 255))));
}
Constructors
LinearGradient(Vector2, Vector2, RgbaF32, RgbaF32)
Initializes a new instance of the LinearGradient class from one color to another.
public LinearGradient(Vector2 start, Vector2 end, RgbaF32 startColor, RgbaF32 endColor)
Parameters
startVector2Where t is 0.
endVector2Where t is 1.
startColorRgbaF32The color at the start.
endColorRgbaF32The color at the end.
Exceptions
- ArgumentException
A point or color is not finite.
LinearGradient(Vector2, Vector2, params ReadOnlySpan<GradientStop>)
Initializes a new instance of the LinearGradient class.
public LinearGradient(Vector2 start, Vector2 end, params ReadOnlySpan<GradientStop> stops)
Parameters
startVector2Where t is 0, in paint coordinates.
endVector2Where t is 1.
stopsReadOnlySpan<GradientStop>The stops; at least one.
Exceptions
- ArgumentException
A point is not finite, or there are no stops.
Properties
End
Gets where t is 1. A gradient whose end is its start has no extent and draws as Skia draws one: the last color for Clamp, the mean color for Repeat and Mirror, nothing for Decal.
public Vector2 End { get; init; }
Property Value
Exceptions
- ArgumentException
The point is not finite.
Start
Gets where t is 0, in paint coordinates.
public Vector2 Start { get; init; }
Property Value
Exceptions
- ArgumentException
The point is not finite.