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 CanvasGradientProperties
| Name | Description |
|---|---|
| ColorInterpolationMethod | 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. |
| HueInterpolationMethod | 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. |
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
| Name | Description |
|---|---|
| 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.csAdds 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.
Parameters
offsetdouble- The offset of the stop, from 0 to 1.
colorstring- A CSS color (
currentcoloris opaque black).
Exceptions
DomException- An
IndexSizeErrorwhen the offset is out of range, aSyntaxErrorwhen the color cannot be parsed.