CanvasFilter Class

  • Experimental (WEBPLATEXP0021)

A filter of the 2D contexts described by a list of filter primitives (https://github.com/whatwg/html/issues/5621, the explainer): the CanvasRenderingContext2DBase.Filter of a context, or the filter of a layer (BeginLayerOptions.Filter). The primitives apply in sRGB, in the order of the list, except the noise of turbulence, which is generated in linearRGB as the one of an SVG feTurbulence element (as in Chromium).

[Experimental("WEBPLATEXP0021", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public sealed class CanvasFilter

Remarks

A primitive is described by a dictionary of strings (record<DOMString, any>) whose name is gaussianBlur (stdDeviation), dropShadow (dx, dy, stdDeviation, floodColor, floodOpacity), colorMatrix (type, values), componentTransfer (funcR, funcG, funcB, funcA: dictionaries of type, tableValues, slope, intercept, amplitude, exponent, offset), convolveMatrix (kernelMatrix, divisor, bias, targetX, targetY, edgeMode, preserveAlpha) or turbulence (baseFrequency, numOctaves, seed, stitchTiles, type), as the attributes of the SVG filter primitives. The values are converted as Chromium converts them: a number is converted as a JavaScript number (null is 0, "10" is 10), and a number of a pair (stdDeviation, baseFrequency) can also be a list of two numbers.

See also

Constructors

NameDescription
CanvasFilter(object?)Creates a filter from the description of a filter primitive, or of a list of filter primitives.

CanvasFilter(object?)

CanvasFilter.cs

Creates a filter from the description of a filter primitive, or of a list of filter primitives.

public CanvasFilter(object? filters)

Parameters

filters object?
The description of a filter primitive (an IReadOnlyDictionary<TKey, TValue> of strings), or a list of descriptions applied in this order. The values are null, strings, booleans, numbers, lists or dictionaries of strings.

Exceptions

TypeErrorException
The description is not valid (e.g. it is not a dictionary or a list, or a number is not finite).

Remarks

As in Chromium, a primitive without a name, or with an unknown name, is ignored.

See also