Class GradientInterpolation
How a gradient mixes its stops: the color space, as CSS Color 4 defines them, and for Oklch the way around the hue circle.
public sealed record GradientInterpolation : IEquatable<GradientInterpolation>
- Inheritance
-
GradientInterpolation
- 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))));
}
Properties
Encoded
Gets mixing in the stored encoded values: the default.
public static GradientInterpolation Encoded { get; }
Property Value
GdiPlusGamma
Gets GDI+'s gamma-corrected mixing (GdiPlusGamma).
public static GradientInterpolation GdiPlusGamma { get; }
Property Value
Examples
// LinearGradientBrush with GammaCorrection = true: GDI+'s 16 gamma-2.2 steps between the colors.
var brush = new LinearGradient(new Vector2(0, 0), new Vector2(256, 0), new GradientStop(0, Rgba8.Black), new GradientStop(1, Rgba8.White))
{
Interpolation = GradientInterpolation.GdiPlusGamma,
};
using (RasterCanvas<Rgb8> canvas = raster.CreateCanvas())
{
canvas.FillRect(new RectF(0, 0, 256, 16), brush);
}
Hue
Gets the way around the hue circle; used by Oklch only.
public HueMethod Hue { get; }
Property Value
LinearSrgb
Gets mixing in linear-light sRGB.
public static GradientInterpolation LinearSrgb { get; }
Property Value
Oklab
Gets mixing in Oklab.
public static GradientInterpolation Oklab { get; }
Property Value
Space
Gets the color space.
public InterpolationSpace Space { get; }
Property Value
Methods
Oklch(HueMethod)
Returns mixing in Oklch with a hue method.
public static GradientInterpolation Oklch(HueMethod hue = HueMethod.Shorter)
Parameters
hueHueMethodThe way around the hue circle.
Returns
- GradientInterpolation
The interpolation.
Exceptions
- ArgumentOutOfRangeException
hueis not defined.