CanvasGradient Class

A gradient of a canvas (https://html.spec.whatwg.org/multipage/canvas.html#canvasgradient): created by createLinearGradient(), createRadialGradient() and createConicGradient(), it is a fill or stroke style whose geometry is in the coordinates of the drawing operations that use it.

public sealed class CanvasGradient

Properties

NameDescription
ColorInterpolationMethodGets or sets the color space the colors of the gradient are interpolated in (https://github.com/whatwg/html/pull/10986): srgb, srgb-linear, display-p3, display-p3-linear, a98-rgb, prophoto-rgb, rec2020, lab, oklab, xyz, xyz-d50, xyz-d65, or the polar color spaces hsl, hwb, lch and oklch, whose hues are interpolated with CanvasGradient.HueInterpolationMethod. The other values are ignored. When it is not set, the value is srgb, but the colors are interpolated as in the CSS gradients (as in the browsers): in sRGB when all the stops are legacy sRGB colors, else in Oklab.
HueInterpolationMethodGets or sets how the hues are interpolated in the polar color spaces of CanvasGradient.ColorInterpolationMethod (https://drafts.csswg.org/css-color-4/#hue-interpolation): shorter (the default), longer, increasing or decreasing. The other values are ignored.

ColorInterpolationMethod

CanvasGradient.cs
  • Experimental (WEBPLATEXP0019)

Gets or sets the color space the colors of the gradient are interpolated in (https://github.com/whatwg/html/pull/10986): srgb, srgb-linear, display-p3, display-p3-linear, a98-rgb, prophoto-rgb, rec2020, lab, oklab, xyz, xyz-d50, xyz-d65, or the polar color spaces hsl, hwb, lch and oklch, whose hues are interpolated with CanvasGradient.HueInterpolationMethod. The other values are ignored. When it is not set, the value is srgb, but the colors are interpolated as in the CSS gradients (as in the browsers): in sRGB when all the stops are legacy sRGB colors, else in Oklab.

[Experimental("WEBPLATEXP0019", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public string ColorInterpolationMethod { get; set; }

HueInterpolationMethod

CanvasGradient.cs
  • Experimental (WEBPLATEXP0019)

Gets or sets how the hues are interpolated in the polar color spaces of CanvasGradient.ColorInterpolationMethod (https://drafts.csswg.org/css-color-4/#hue-interpolation): shorter (the default), longer, increasing or decreasing. The other values are ignored.

[Experimental("WEBPLATEXP0019", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public string HueInterpolationMethod { get; set; }

Methods

NameDescription
AddColorStop(double, string)Adds a color stop (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvasgradient-addcolorstop): a stop at the same offset as existing stops is placed after them.

AddColorStop(double, string)

CanvasGradient.cs

Adds a color stop (https://html.spec.whatwg.org/multipage/canvas.html#dom-canvasgradient-addcolorstop): a stop at the same offset as existing stops is placed after them.

public void AddColorStop(double offset, string color)

Parameters

offset double
The offset of the stop, from 0 to 1.
color string
A CSS color (currentcolor is opaque black).

Exceptions

DomException
An IndexSizeError when the offset is out of range, a SyntaxError when the color cannot be parsed.

See also