CanvasRenderingContext2DBase Class

The members shared by the 2D rendering contexts of the canvases (https://html.spec.whatwg.org/multipage/canvas.html#2dcontext): CanvasRenderingContext2D (canvas.getContext("2d")) and OffscreenCanvasRenderingContext2D.

public abstract class CanvasRenderingContext2DBase

Remarks

The library implements the state, the paths, the styles, the text layout (with the managed font reader and text shaping) and the drawing model of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#drawing-model); each drawing operation is a small display list (the clip region, the shadow, the compositing operator and the filters, then the shape in the coordinates of the current transformation matrix), rasterized on the bitmap of the canvas by the rendering backend (BrowsingContextOptions.RenderingBackend). Without a backend there is no context: getContext("2d") returns null.

The paths and the text are stored as the specification describes them: the current default path in the coordinates of the canvas (its points are transformed when they are added), a Path2D in the coordinates where it is drawn.

See also

Properties

NameDescription
DirectionGets or sets the direction of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-direction).
FillStyleGets or sets the style of the fills (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fillstyle): a CSS color (serialized when it is read), a CanvasGradient or a CanvasPattern. The strings that are not colors are ignored.
FilterGets or sets the filter of the drawing operations (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-filter): none or a list of CSS filter functions (the lengths are resolved against the current font), or a CanvasFilter (a proposal, https://github.com/whatwg/html/issues/5621); the strings that are not filters and null are ignored. The references to SVG filter elements (url()) are resolved in the document of the canvas element (an OffscreenCanvas does not filter its drawings with them).
FontGets or sets the font (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-font): a value of the CSS font shorthand (the relative values are resolved against the font of the canvas element, or 10px sans-serif), serialized with its size in px and without line height. The values that cannot be parsed are ignored. Setting the font resets CanvasRenderingContext2DBase.FontStretch and CanvasRenderingContext2DBase.FontVariantCaps to the values of the shorthand (as in the browsers, CanvasRenderingContext2DBase.FontKerning is kept).
FontKerningGets or sets the kerning of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontkerning).
FontStretchGets or sets the width of the font (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontstretch).
FontVariantCapsGets or sets the capitals of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps): the OpenType features of the capitals (the small capitals are not synthesized).
GlobalAlphaGets or sets the alpha applied to the drawing operations (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-globalalpha): the values outside of [0, 1] are ignored.
GlobalCompositeOperationGets or sets the compositing operator or the blend mode of the drawing operations (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-globalcompositeoperation): a value of <blend-mode> or of the Porter-Duff operators of Compositing and Blending; the other values are ignored.
ImageSmoothingEnabledGets or sets whether the images are smoothed when they are scaled (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-imagesmoothingenabled).
ImageSmoothingQualityGets or sets the quality of the image smoothing (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-imagesmoothingquality).
LangGets or sets the language of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-lang): a BCP 47 language tag, or inherit.
LetterSpacingGets or sets the spacing between the letters (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-letterspacing): a CSS length (the font-relative lengths are resolved against the current font when the text is drawn); other values are ignored.
LineCapGets or sets the shape of the ends of the lines (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linecap).
LineDashOffsetGets or sets the phase of the dash list (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linedashoffset): non-finite values are ignored.
LineJoinGets or sets the shape of the corners of the lines (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linejoin).
LineWidthGets or sets the width of the lines (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linewidth): zero, negative and non-finite values are ignored.
MiterLimitGets or sets the miter limit ratio (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-miterlimit): zero, negative and non-finite values are ignored.
ShadowBlurGets or sets the blur of the shadows (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowblur): the negative values are ignored.
ShadowColorGets or sets the color of the shadows (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowcolor): the strings that are not colors are ignored.
ShadowOffsetXGets or sets the horizontal offset of the shadows (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowoffsetx).
ShadowOffsetYGets or sets the vertical offset of the shadows (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowoffsety).
StrokeStyleGets or sets the style of the strokes (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-strokestyle): a CSS color (serialized when it is read), a CanvasGradient or a CanvasPattern. The strings that are not colors are ignored.
TextAlignGets or sets the alignment of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-textalign).
TextBaselineGets or sets the baseline of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-textbaseline).
TextRenderingGets or sets the rendering hint of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-textrendering): optimizeSpeed disables the kerning, as text-rendering.
WordSpacingGets or sets the spacing between the words (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-wordspacing): a CSS length (the font-relative lengths are resolved against the current font when the text is drawn); other values are ignored.

Gets or sets the direction of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-direction).

public CanvasDirection Direction { get; set; }

Gets or sets the style of the fills (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fillstyle): a CSS color (serialized when it is read), a CanvasGradient or a CanvasPattern. The strings that are not colors are ignored.

public object FillStyle { get; set; }

Gets or sets the filter of the drawing operations (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-filter): none or a list of CSS filter functions (the lengths are resolved against the current font), or a CanvasFilter (a proposal, https://github.com/whatwg/html/issues/5621); the strings that are not filters and null are ignored. The references to SVG filter elements (url()) are resolved in the document of the canvas element (an OffscreenCanvas does not filter its drawings with them).

public object Filter { get; set; }

Property value

object

Exceptions

ArgumentException
The value is not a string or a CanvasFilter.

See also

Gets or sets the font (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-font): a value of the CSS font shorthand (the relative values are resolved against the font of the canvas element, or 10px sans-serif), serialized with its size in px and without line height. The values that cannot be parsed are ignored. Setting the font resets CanvasRenderingContext2DBase.FontStretch and CanvasRenderingContext2DBase.FontVariantCaps to the values of the shorthand (as in the browsers, CanvasRenderingContext2DBase.FontKerning is kept).

public string Font { get; set; }

Gets or sets the kerning of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontkerning).

public CanvasFontKerning FontKerning { get; set; }

Gets or sets the width of the font (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontstretch).

public CanvasFontStretch FontStretch { get; set; }

Gets or sets the capitals of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fontvariantcaps): the OpenType features of the capitals (the small capitals are not synthesized).

public CanvasFontVariantCaps FontVariantCaps { get; set; }

Gets or sets the alpha applied to the drawing operations (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-globalalpha): the values outside of [0, 1] are ignored.

public double GlobalAlpha { get; set; }

GlobalCompositeOperation

CanvasRenderingContext2DBase.cs

Gets or sets the compositing operator or the blend mode of the drawing operations (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-globalcompositeoperation): a value of <blend-mode> or of the Porter-Duff operators of Compositing and Blending; the other values are ignored.

public string GlobalCompositeOperation { get; set; }

ImageSmoothingEnabled

CanvasRenderingContext2DBase.cs

Gets or sets whether the images are smoothed when they are scaled (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-imagesmoothingenabled).

public bool ImageSmoothingEnabled { get; set; }

ImageSmoothingQuality

CanvasRenderingContext2DBase.cs

Gets or sets the quality of the image smoothing (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-imagesmoothingquality).

public ImageSmoothingQuality ImageSmoothingQuality { get; set; }

Gets or sets the language of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-lang): a BCP 47 language tag, or inherit.

public string Lang { get; set; }

Gets or sets the spacing between the letters (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-letterspacing): a CSS length (the font-relative lengths are resolved against the current font when the text is drawn); other values are ignored.

public string LetterSpacing { get; set; }

Gets or sets the shape of the ends of the lines (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linecap).

public CanvasLineCap LineCap { get; set; }

Gets or sets the phase of the dash list (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linedashoffset): non-finite values are ignored.

public double LineDashOffset { get; set; }

Gets or sets the shape of the corners of the lines (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linejoin).

public CanvasLineJoin LineJoin { get; set; }

Gets or sets the width of the lines (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-linewidth): zero, negative and non-finite values are ignored.

public double LineWidth { get; set; }

Gets or sets the miter limit ratio (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-miterlimit): zero, negative and non-finite values are ignored.

public double MiterLimit { get; set; }

Gets or sets the blur of the shadows (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowblur): the negative values are ignored.

public double ShadowBlur { get; set; }

Gets or sets the color of the shadows (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowcolor): the strings that are not colors are ignored.

public string ShadowColor { get; set; }

Gets or sets the horizontal offset of the shadows (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowoffsetx).

public double ShadowOffsetX { get; set; }

Gets or sets the vertical offset of the shadows (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-shadowoffsety).

public double ShadowOffsetY { get; set; }

Gets or sets the style of the strokes (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-strokestyle): a CSS color (serialized when it is read), a CanvasGradient or a CanvasPattern. The strings that are not colors are ignored.

public object StrokeStyle { get; set; }

Gets or sets the alignment of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-textalign).

public CanvasTextAlign TextAlign { get; set; }

Gets or sets the baseline of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-textbaseline).

public CanvasTextBaseline TextBaseline { get; set; }

Gets or sets the rendering hint of the texts (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-textrendering): optimizeSpeed disables the kerning, as text-rendering.

public CanvasTextRendering TextRendering { get; set; }

Gets or sets the spacing between the words (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-wordspacing): a CSS length (the font-relative lengths are resolved against the current font when the text is drawn); other values are ignored.

public string WordSpacing { get; set; }

Methods

NameDescription
Arc(double, double, double, double, double, bool)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-arc
ArcTo(double, double, double, double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-arcto
BeginLayer(BeginLayerOptions?)Saves the drawing state on the stack and starts a layer (https://github.com/whatwg/html/pull/9537): the following drawing operations are drawn into a transparent layer, which CanvasRenderingContext2DBase.EndLayer draws on the canvas as one image. In the layer, the global alpha, the compositing operator, the shadows, the filter and the clip region are reset; they apply to the layer when it is drawn. The transformation matrix is not reset.
BeginPath()Empties the current default path (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-beginpath).
BezierCurveTo(double, double, double, double, double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-beziercurveto
ClearRect(double, double, double, double)Clears a rectangle to transparent black (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-clearrect): the clip region and the current transformation matrix apply, the shadows, the global alpha, the compositing and the filters do not.
Clip(CanvasFillRule)Intersects the clip region with the current default path (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-clip).
Clip(Path2D, CanvasFillRule)Intersects the clip region with a path (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-clip).
ClosePath()https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-closepath
CreateConicGradient(double, double, double)Creates a conic gradient around (x, y) (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createconicgradient).
CreateImageData(ImageData)Creates a transparent black image data of the size and color space of another one (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createimagedata-imagedata).
CreateImageData(int, int, ImageDataSettings?)Creates a transparent black image data (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createimagedata).
CreateLinearGradient(double, double, double, double)Creates a linear gradient from (x0, y0) to (x1, y1) (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createlineargradient).
CreatePattern(object?, string)Creates a pattern of an image (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createpattern), or returns null when the image cannot be drawn (not fully decodable).
CreateRadialGradient(double, double, double, double, double, double)Creates a radial gradient between two circles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createradialgradient).
DrawElementImage(object?, double, double, DrawElementImageOptions?)Draws the last snapshot of a drawable element of the canvas at its default size (see HtmlCanvasElement.GetElementImageDefaultSize), and sets its canvas transform to where it is drawn (unless DrawElementImageOptions.PreserveElementGeometry is true).
DrawElementImage(object?, double, double, double, double, DrawElementImageOptions?)Draws the last snapshot of a drawable element of the canvas scaled to a rectangle (see CanvasRenderingContext2DBase.DrawElementImage).
DrawElementImage(object?, double, double, double, double, double, double, DrawElementImageOptions?)Draws a rectangle of the last snapshot of a drawable element of the canvas at its size (see CanvasRenderingContext2DBase.DrawElementImage). The source rectangle is in the coordinates of the image (the pixels of the bitmap of the canvas), and can extend beyond the border box of the element (its ink overflow).
DrawElementImage(object?, double, double, double, double, double, double, double, double, DrawElementImageOptions?)Draws a rectangle of the last snapshot of a drawable element of the canvas scaled to a rectangle (see CanvasRenderingContext2DBase.DrawElementImage).
DrawFocusIfNeeded(Element)Draws a focus ring around the current default path when the element is focused and is a descendant of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawfocusifneeded).
DrawFocusIfNeeded(Path2D, Element)Draws a focus ring around a path when the element is focused and is a descendant of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawfocusifneeded).
DrawImage(object?, double, double)Draws an image at its natural size (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawimage).
DrawImage(object?, double, double, double, double)Draws an image scaled to a rectangle (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawimage).
DrawImage(object?, double, double, double, double, double, double, double, double)Draws a rectangle of an image scaled to a rectangle (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawimage).
Ellipse(double, double, double, double, double, double, double, bool)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ellipse
EndLayer()Restores the drawing state saved by CanvasRenderingContext2DBase.BeginLayer and draws the layer on the canvas (or on the parent layer) with the global alpha, the compositing operator, the shadow, the filter and the clip region of this state.
Fill(CanvasFillRule)Fills the current default path with the fill style (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fill).
Fill(Path2D, CanvasFillRule)Fills a path with the fill style (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fill).
FillGlyphRun(CanvasGlyphRun, double, double)Fills a glyph run of a shaped text with the fill style, the alignment point of the shaped text at (x, y).
FillGlyphRuns(IReadOnlyList<CanvasGlyphRun>, double, double)Fills glyph runs of shaped texts with the fill style, the alignment point of each shaped text at (x, y).
FillRect(double, double, double, double)Fills a rectangle with the fill style (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fillrect).
FillText(string, double, double, double?)Fills a text at a point with the fill style (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-filltext).
FillTextCluster(TextCluster, double, double, TextClusterOptions?)Fills a cluster of a measured text (https://github.com/whatwg/html/pull/11000) with the fill style: the glyphs of the cluster, with the font and the text styles of the measurement, are drawn with their alignment point at (x + TextCluster.X, y + TextCluster.Y). Drawing all the clusters of a text at the same point draws the text as CanvasRenderingContext2DBase.FillText at that point.
GetContextAttributes()Returns the settings of the context (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getcontextattributes).
GetImageData(int, int, int, int, ImageDataSettings?)Returns the pixels of a rectangle of the bitmap (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getimagedata): not premultiplied, in the requested color space; the pixels outside of the bitmap are transparent black.
GetLineDash()Returns a copy of the dash list (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getlinedash).
GetTransform()Returns a copy of the current transformation matrix (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-gettransform).
IsContextLost()Whether the context is lost (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-iscontextlost): never.
IsPointInPath(Path2D, double, double, CanvasFillRule)Returns whether a point (in the coordinates of the canvas, not transformed) is inside a path transformed by the current transformation matrix.
IsPointInPath(double, double, CanvasFillRule)Returns whether a point (in the coordinates of the canvas, not transformed) is inside the current default path (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinpath); the points of the path are inside.
IsPointInStroke(Path2D, double, double)Returns whether a point (in the coordinates of the canvas, not transformed) is inside the stroke of a path with the line styles.
IsPointInStroke(double, double)Returns whether a point (in the coordinates of the canvas, not transformed) is inside the stroke of the current default path with the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinstroke).
LineTo(double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-lineto
MeasureText(string)Measures a text with the current font and text styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-measuretext).
MoveTo(double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-moveto
PutImageData(ImageData, int, int)Replaces the pixels of the bitmap with the pixels of an image data (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-putimagedata).
PutImageData(ImageData, int, int, int, int, int, int)Replaces the pixels of the bitmap with the pixels of a dirty rectangle of an image data (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-putimagedata): the pixels are not composited, and the current transformation matrix, the clip region, the global alpha and the shadows do not apply.
QuadraticCurveTo(double, double, double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-quadraticcurveto
Rect(double, double, double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-rect
Reset()Resets the context to its default state (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-reset): the bitmap is cleared, the drawing state and its stack, and the current default path are reset, and the open layers are discarded.
ResetTransform()https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-resettransform
Restore()Pops the drawing state from the stack (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-restore); does nothing when the stack is empty.
Rotate(double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-rotate: a clockwise rotation by an angle in radians.
RoundRect(double, double, double, double, object?)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-roundrect
Save()Pushes a copy of the drawing state on the stack (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-save).
Scale(double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-scale
SetLineDash(IReadOnlyList<double>)Sets the dash list of the lines (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-setlinedash): a list with a negative or non-finite value is ignored, a list with an odd number of values is repeated.
SetTransform(DomMatrix2DInit?)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-settransform-matrix
SetTransform(double, double, double, double, double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-settransform
ShapeText(string)Shapes a text with the current font and text styles: the returned CanvasShapedText gives its glyph runs and clusters, drawn later by CanvasRenderingContext2DBase.FillGlyphRuns and CanvasRenderingContext2DBase.StrokeGlyphRuns with the font, the text styles, the direction, the alignment and the baseline of the context at this time.
Stroke()Strokes the current default path with the stroke style and the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-stroke).
Stroke(Path2D)Strokes a path with the stroke style and the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-stroke).
StrokeGlyphRun(CanvasGlyphRun, double, double)Strokes a glyph run of a shaped text with the stroke style and the line styles, the alignment point of the shaped text at (x, y).
StrokeGlyphRuns(IReadOnlyList<CanvasGlyphRun>, double, double)Strokes glyph runs of shaped texts with the stroke style and the line styles, the alignment point of each shaped text at (x, y).
StrokeRect(double, double, double, double)Strokes the outline of a rectangle with the stroke style and the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-strokerect).
StrokeText(string, double, double, double?)Strokes a text at a point with the stroke style and the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-stroketext).
StrokeTextCluster(TextCluster, double, double, TextClusterOptions?)Strokes a cluster of a measured text (https://github.com/whatwg/html/pull/11000) with the stroke style and the line styles: see CanvasRenderingContext2DBase.FillTextCluster.
Transform(double, double, double, double, double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-transform
Translate(double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-translate

Arc(double, double, double, double, double, bool)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-arc

public void Arc(double x, double y, double radius, double startAngle, double endAngle, bool counterclockwise = false)

Parameters

x double
y double
radius double
startAngle double
endAngle double
counterclockwise bool

Exceptions

DomException
An IndexSizeError when the radius is negative.

See also

ArcTo(double, double, double, double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-arcto

public void ArcTo(double x1, double y1, double x2, double y2, double radius)

Parameters

x1 double
y1 double
x2 double
y2 double
radius double

Exceptions

DomException
An IndexSizeError when the radius is negative.

See also

BeginLayer(BeginLayerOptions?)

CanvasRenderingContext2DBase.Layers.cs
  • Experimental (WEBPLATEXP0017)

Saves the drawing state on the stack and starts a layer (https://github.com/whatwg/html/pull/9537): the following drawing operations are drawn into a transparent layer, which CanvasRenderingContext2DBase.EndLayer draws on the canvas as one image. In the layer, the global alpha, the compositing operator, the shadows, the filter and the clip region are reset; they apply to the layer when it is drawn. The transformation matrix is not reset.

[Experimental("WEBPLATEXP0017", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void BeginLayer(BeginLayerOptions? options = null)

Parameters

options BeginLayerOptions?
The options of the layer: its filter, a CSS filter or a CanvasFilter (or the description of one) applied to the layer before the filter of the state, in the coordinates of the current transformation matrix.

Exceptions

TypeErrorException
The filter is the description of a CanvasFilter that is not valid: the layer is not opened.

Remarks

While a layer is open, the pixels of the canvas cannot be read (getImageData(), toDataURL(), drawImage() of the canvas...): these methods throw an InvalidStateError. The canvas displays the pixels drawn before the layer was opened.

See also

Empties the current default path (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-beginpath).

public void BeginPath()

BezierCurveTo(double, double, double, double, double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-beziercurveto

public void BezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y)

ClearRect(double, double, double, double)

CanvasRenderingContext2DBase.cs

Clears a rectangle to transparent black (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-clearrect): the clip region and the current transformation matrix apply, the shadows, the global alpha, the compositing and the filters do not.

public void ClearRect(double x, double y, double w, double h)

Clip overloads

Intersects the clip region with the current default path (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-clip).

public void Clip(CanvasFillRule fillRule = CanvasFillRule.NonZero)

Clip(Path2D, CanvasFillRule)

CanvasRenderingContext2DBase.cs

Intersects the clip region with a path (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-clip).

public void Clip(Path2D path, CanvasFillRule fillRule = CanvasFillRule.NonZero)

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-closepath

public void ClosePath()

CreateConicGradient(double, double, double)

CanvasRenderingContext2DBase.cs

Creates a conic gradient around (x, y) (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createconicgradient).

public CanvasGradient CreateConicGradient(double startAngle, double x, double y)

CreateImageData overloads

CreateImageData(ImageData)

CanvasRenderingContext2DBase.Images.cs

Creates a transparent black image data of the size and color space of another one (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createimagedata-imagedata).

public ImageData CreateImageData(ImageData imageData)

CreateImageData(int, int, ImageDataSettings?)

CanvasRenderingContext2DBase.Images.cs

Creates a transparent black image data (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createimagedata).

public ImageData CreateImageData(int sw, int sh, ImageDataSettings? settings = null)
Parameters
sw int
The width (its absolute value is used).
sh int
The height (its absolute value is used).
settings ImageDataSettings?
The color space (the color space of the canvas by default) and the format of the pixels.
Returns

ImageData

Exceptions
DomException
An IndexSizeError when the width or the height is zero.
See also

CreateLinearGradient(double, double, double, double)

CanvasRenderingContext2DBase.cs

Creates a linear gradient from (x0, y0) to (x1, y1) (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createlineargradient).

public CanvasGradient CreateLinearGradient(double x0, double y0, double x1, double y1)

CreatePattern(object?, string)

CanvasRenderingContext2DBase.Images.cs

Creates a pattern of an image (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createpattern), or returns null when the image cannot be drawn (not fully decodable).

public CanvasPattern? CreatePattern(object? image, string repetition)

Parameters

image object?
An img, svg:image, video or canvas element, an ImageBitmap, an OffscreenCanvas or a CssImageValue (the image of a URL fetched for the styles of the document).
repetition string
repeat (or the empty string), repeat-x, repeat-y or no-repeat.

Returns

CanvasPattern?

Exceptions

DomException
An InvalidStateError when the image is broken, or a canvas or a bitmap without pixels; a SyntaxError when the repetition is invalid.

See also

CreateRadialGradient(double, double, double, double, double, double)

CanvasRenderingContext2DBase.cs

Creates a radial gradient between two circles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-createradialgradient).

public CanvasGradient CreateRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1)

Parameters

x0 double
y0 double
r0 double
x1 double
y1 double
r1 double

Returns

CanvasGradient

Exceptions

TypeErrorException
An argument is not finite.
DomException
An IndexSizeError when a radius is negative.

See also

DrawElementImage overloads

DrawElementImage(object?, double, double, DrawElementImageOptions?)

CanvasRenderingContext2DBase.ElementImages.cs
  • Experimental (WEBPLATEXP0023)

Draws the last snapshot of a drawable element of the canvas at its default size (see HtmlCanvasElement.GetElementImageDefaultSize), and sets its canvas transform to where it is drawn (unless DrawElementImageOptions.PreserveElementGeometry is true).

[Experimental("WEBPLATEXP0023", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void DrawElementImage(object? element, double dx, double dy, DrawElementImageOptions? options = null)
Parameters
element object?
A drawable element of the canvas, or an ElementImage of the canvas.
dx double
The x coordinate of the destination.
dy double
The y coordinate of the destination.
options DrawElementImageOptions?
The options.
Exceptions
DomException
An InvalidStateError when the element is not a drawable element of the canvas, it has no snapshot, or the image is closed.
See also

DrawElementImage(object?, double, double, double, double, DrawElementImageOptions?)

CanvasRenderingContext2DBase.ElementImages.cs
  • Experimental (WEBPLATEXP0023)

Draws the last snapshot of a drawable element of the canvas scaled to a rectangle (see CanvasRenderingContext2DBase.DrawElementImage).

[Experimental("WEBPLATEXP0023", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void DrawElementImage(object? element, double dx, double dy, double dwidth, double dheight, DrawElementImageOptions? options = null)
Parameters
element object?
A drawable element of the canvas, or an ElementImage of the canvas.
dx double
The x coordinate of the destination.
dy double
The y coordinate of the destination.
dwidth double
The width of the destination.
dheight double
The height of the destination.
options DrawElementImageOptions?
The options.
Exceptions
DomException
An InvalidStateError when the element is not a drawable element of the canvas, it has no snapshot, or the image is closed.
See also

DrawElementImage(object?, double, double, double, double, double, double, DrawElementImageOptions?)

CanvasRenderingContext2DBase.ElementImages.cs
  • Experimental (WEBPLATEXP0023)

Draws a rectangle of the last snapshot of a drawable element of the canvas at its size (see CanvasRenderingContext2DBase.DrawElementImage). The source rectangle is in the coordinates of the image (the pixels of the bitmap of the canvas), and can extend beyond the border box of the element (its ink overflow).

[Experimental("WEBPLATEXP0023", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void DrawElementImage(object? element, double sx, double sy, double swidth, double sheight, double dx, double dy, DrawElementImageOptions? options = null)
Parameters
element object?
A drawable element of the canvas, or an ElementImage of the canvas.
sx double
The x coordinate of the source rectangle.
sy double
The y coordinate of the source rectangle.
swidth double
The width of the source rectangle.
sheight double
The height of the source rectangle.
dx double
The x coordinate of the destination.
dy double
The y coordinate of the destination.
options DrawElementImageOptions?
The options.
Exceptions
DomException
An InvalidStateError when the element is not a drawable element of the canvas, it has no snapshot, or the image is closed.
See also

DrawElementImage(object?, double, double, double, double, double, double, double, double, DrawElementImageOptions?)

CanvasRenderingContext2DBase.ElementImages.cs
  • Experimental (WEBPLATEXP0023)

Draws a rectangle of the last snapshot of a drawable element of the canvas scaled to a rectangle (see CanvasRenderingContext2DBase.DrawElementImage).

[Experimental("WEBPLATEXP0023", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void DrawElementImage(object? element, double sx, double sy, double swidth, double sheight, double dx, double dy, double dwidth, double dheight, DrawElementImageOptions? options = null)
Parameters
element object?
A drawable element of the canvas, or an ElementImage of the canvas.
sx double
The x coordinate of the source rectangle.
sy double
The y coordinate of the source rectangle.
swidth double
The width of the source rectangle.
sheight double
The height of the source rectangle.
dx double
The x coordinate of the destination.
dy double
The y coordinate of the destination.
dwidth double
The width of the destination.
dheight double
The height of the destination.
options DrawElementImageOptions?
The options.
Exceptions
DomException
An InvalidStateError when the element is not a drawable element of the canvas, it has no snapshot, or the image is closed.
See also

DrawFocusIfNeeded overloads

DrawFocusIfNeeded(Element)

CanvasRenderingContext2DBase.cs

Draws a focus ring around the current default path when the element is focused and is a descendant of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawfocusifneeded).

public void DrawFocusIfNeeded(Element element)

DrawFocusIfNeeded(Path2D, Element)

CanvasRenderingContext2DBase.cs

Draws a focus ring around a path when the element is focused and is a descendant of the canvas (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawfocusifneeded).

public void DrawFocusIfNeeded(Path2D path, Element element)

DrawImage overloads

DrawImage(object?, double, double)

CanvasRenderingContext2DBase.Images.cs

Draws an image at its natural size (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawimage).

public void DrawImage(object? image, double dx, double dy)
Parameters
image object?
An img, svg:image, video or canvas element, an ImageBitmap, an OffscreenCanvas or a CssImageValue (the image of a URL fetched for the styles of the document).
dx double
The x coordinate of the destination.
dy double
The y coordinate of the destination.
Exceptions
DomException
An InvalidStateError when the image is broken, or a canvas or a bitmap without pixels.
See also

DrawImage(object?, double, double, double, double)

CanvasRenderingContext2DBase.Images.cs

Draws an image scaled to a rectangle (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawimage).

public void DrawImage(object? image, double dx, double dy, double dw, double dh)
Parameters
image object?
An img, svg:image, video or canvas element, an ImageBitmap, an OffscreenCanvas or a CssImageValue (the image of a URL fetched for the styles of the document).
dx double
The x coordinate of the destination.
dy double
The y coordinate of the destination.
dw double
The width of the destination.
dh double
The height of the destination.
Exceptions
DomException
An InvalidStateError when the image is broken, or a canvas or a bitmap without pixels.
See also

DrawImage(object?, double, double, double, double, double, double, double, double)

CanvasRenderingContext2DBase.Images.cs

Draws a rectangle of an image scaled to a rectangle (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-drawimage).

public void DrawImage(object? image, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
Parameters
image object?
An img, svg:image, video or canvas element, an ImageBitmap, an OffscreenCanvas or a CssImageValue (the image of a URL fetched for the styles of the document).
sx double
The x coordinate of the source rectangle, in image pixels.
sy double
The y coordinate of the source rectangle, in image pixels.
sw double
The width of the source rectangle.
sh double
The height of the source rectangle.
dx double
The x coordinate of the destination.
dy double
The y coordinate of the destination.
dw double
The width of the destination.
dh double
The height of the destination.
Exceptions
DomException
An InvalidStateError when the image is broken, or a canvas or a bitmap without pixels.
See also

Ellipse(double, double, double, double, double, double, double, bool)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ellipse

public void Ellipse(double x, double y, double radiusX, double radiusY, double rotation, double startAngle, double endAngle, bool counterclockwise = false)

Parameters

x double
y double
radiusX double
radiusY double
rotation double
startAngle double
endAngle double
counterclockwise bool

Exceptions

DomException
An IndexSizeError when a radius is negative.

See also

  • Experimental (WEBPLATEXP0017)

Restores the drawing state saved by CanvasRenderingContext2DBase.BeginLayer and draws the layer on the canvas (or on the parent layer) with the global alpha, the compositing operator, the shadow, the filter and the clip region of this state.

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

Exceptions

DomException
An InvalidStateError when the last state of the stack was not pushed by CanvasRenderingContext2DBase.BeginLayer (no layer is open, or a CanvasRenderingContext2DBase.Save is not restored).

See also

Fill overloads

Fills the current default path with the fill style (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fill).

public void Fill(CanvasFillRule fillRule = CanvasFillRule.NonZero)

Fill(Path2D, CanvasFillRule)

CanvasRenderingContext2DBase.cs

Fills a path with the fill style (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fill).

public void Fill(Path2D path, CanvasFillRule fillRule = CanvasFillRule.NonZero)

FillGlyphRun(CanvasGlyphRun, double, double)

CanvasRenderingContext2DBase.TextClusters.cs
  • Experimental (WEBPLATEXP0025)

Fills a glyph run of a shaped text with the fill style, the alignment point of the shaped text at (x, y).

[Experimental("WEBPLATEXP0025", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void FillGlyphRun(CanvasGlyphRun glyphRun, double x, double y)

Parameters

glyphRun CanvasGlyphRun
The glyph run, returned by CanvasShapedText.GlyphRuns or CanvasShapedText.GlyphClusters.
x double
The x coordinate of the alignment point of the shaped text.
y double
The y coordinate of the baseline of the shaped text.

See also

FillGlyphRuns(IReadOnlyList<CanvasGlyphRun>, double, double)

CanvasRenderingContext2DBase.TextClusters.cs
  • Experimental (WEBPLATEXP0025)

Fills glyph runs of shaped texts with the fill style, the alignment point of each shaped text at (x, y).

[Experimental("WEBPLATEXP0025", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void FillGlyphRuns(IReadOnlyList<CanvasGlyphRun> glyphRuns, double x, double y)

Parameters

glyphRuns IReadOnlyList<CanvasGlyphRun>
The glyph runs, returned by CanvasShapedText.GlyphRuns or CanvasShapedText.GlyphClusters.
x double
The x coordinate of the alignment point of the shaped texts.
y double
The y coordinate of the baseline of the shaped texts.

See also

FillRect(double, double, double, double)

CanvasRenderingContext2DBase.cs

Fills a rectangle with the fill style (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fillrect).

public void FillRect(double x, double y, double w, double h)

FillText(string, double, double, double?)

CanvasRenderingContext2DBase.Text.cs

Fills a text at a point with the fill style (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-filltext).

public void FillText(string text, double x, double y, double? maxWidth = null)

Parameters

text string
The text.
x double
The x coordinate of the alignment point.
y double
The y coordinate of the baseline.
maxWidth double?
The maximum width: a wider text is compressed horizontally; nothing is drawn when it is not positive.

See also

FillTextCluster(TextCluster, double, double, TextClusterOptions?)

CanvasRenderingContext2DBase.TextClusters.cs
  • Experimental (WEBPLATEXP0024)

Fills a cluster of a measured text (https://github.com/whatwg/html/pull/11000) with the fill style: the glyphs of the cluster, with the font and the text styles of the measurement, are drawn with their alignment point at (x + TextCluster.X, y + TextCluster.Y). Drawing all the clusters of a text at the same point draws the text as CanvasRenderingContext2DBase.FillText at that point.

[Experimental("WEBPLATEXP0024", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void FillTextCluster(TextCluster textCluster, double x, double y, TextClusterOptions? options = null)

Parameters

textCluster TextCluster
The cluster, returned by TextMetrics.GetTextClusters.
x double
The x coordinate the position of the cluster is relative to.
y double
The y coordinate the position of the cluster is relative to.
options TextClusterOptions?
The alignment, the baseline and the position (x, y) that replace the ones of the cluster.

See also

GetContextAttributes()

CanvasRenderingContext2DBase.cs

Returns the settings of the context (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getcontextattributes).

public CanvasRenderingContext2DSettings GetContextAttributes()

GetImageData(int, int, int, int, ImageDataSettings?)

CanvasRenderingContext2DBase.Images.cs

Returns the pixels of a rectangle of the bitmap (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getimagedata): not premultiplied, in the requested color space; the pixels outside of the bitmap are transparent black.

public ImageData GetImageData(int sx, int sy, int sw, int sh, ImageDataSettings? settings = null)

Parameters

sx int
sy int
sw int
sh int
settings ImageDataSettings?

Returns

ImageData

Exceptions

DomException
An IndexSizeError when the width or the height is zero, a SecurityError when the canvas is not origin-clean.

See also

Returns a copy of the dash list (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-getlinedash).

public IReadOnlyList<double> GetLineDash()

Returns a copy of the current transformation matrix (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-gettransform).

public DomMatrix GetTransform()

Whether the context is lost (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-iscontextlost): never.

public bool IsContextLost()

IsPointInPath overloads

IsPointInPath(Path2D, double, double, CanvasFillRule)

CanvasRenderingContext2DBase.cs

Returns whether a point (in the coordinates of the canvas, not transformed) is inside a path transformed by the current transformation matrix.

public bool IsPointInPath(Path2D path, double x, double y, CanvasFillRule fillRule = CanvasFillRule.NonZero)

IsPointInPath(double, double, CanvasFillRule)

CanvasRenderingContext2DBase.cs

Returns whether a point (in the coordinates of the canvas, not transformed) is inside the current default path (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinpath); the points of the path are inside.

public bool IsPointInPath(double x, double y, CanvasFillRule fillRule = CanvasFillRule.NonZero)

IsPointInStroke overloads

IsPointInStroke(Path2D, double, double)

CanvasRenderingContext2DBase.cs

Returns whether a point (in the coordinates of the canvas, not transformed) is inside the stroke of a path with the line styles.

public bool IsPointInStroke(Path2D path, double x, double y)

IsPointInStroke(double, double)

CanvasRenderingContext2DBase.cs

Returns whether a point (in the coordinates of the canvas, not transformed) is inside the stroke of the current default path with the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ispointinstroke).

public bool IsPointInStroke(double x, double y)

LineTo(double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-lineto

public void LineTo(double x, double y)

Measures a text with the current font and text styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-measuretext).

public TextMetrics MeasureText(string text)

MoveTo(double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-moveto

public void MoveTo(double x, double y)

PutImageData overloads

PutImageData(ImageData, int, int)

CanvasRenderingContext2DBase.Images.cs

Replaces the pixels of the bitmap with the pixels of an image data (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-putimagedata).

public void PutImageData(ImageData imageData, int dx, int dy)
Parameters
imageData ImageData
dx int
dy int
Exceptions
DomException
An InvalidStateError when the buffer of the image data is detached.
See also

PutImageData(ImageData, int, int, int, int, int, int)

CanvasRenderingContext2DBase.Images.cs

Replaces the pixels of the bitmap with the pixels of a dirty rectangle of an image data (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-putimagedata): the pixels are not composited, and the current transformation matrix, the clip region, the global alpha and the shadows do not apply.

public void PutImageData(ImageData imageData, int dx, int dy, int dirtyX, int dirtyY, int dirtyWidth, int dirtyHeight)
Parameters
imageData ImageData
dx int
dy int
dirtyX int
dirtyY int
dirtyWidth int
dirtyHeight int
Exceptions
DomException
An InvalidStateError when the buffer of the image data is detached.
See also

QuadraticCurveTo(double, double, double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-quadraticcurveto

public void QuadraticCurveTo(double cpx, double cpy, double x, double y)

Rect(double, double, double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-rect

public void Rect(double x, double y, double w, double h)

Resets the context to its default state (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-reset): the bitmap is cleared, the drawing state and its stack, and the current default path are reset, and the open layers are discarded.

public void Reset()

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-resettransform

public void ResetTransform()

Pops the drawing state from the stack (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-restore); does nothing when the stack is empty.

public void Restore()

Exceptions

DomException
An InvalidStateError when the last state of the stack was pushed by CanvasRenderingContext2DBase.BeginLayer.

See also

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-rotate: a clockwise rotation by an angle in radians.

public void Rotate(double angle)

RoundRect(double, double, double, double, object?)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-roundrect

public void RoundRect(double x, double y, double w, double h, object? radii = null)

Parameters

x double
The x coordinate of the rectangle.
y double
The y coordinate of the rectangle.
w double
The width of the rectangle.
h double
The height of the rectangle.
radii object?
A radius (a number or a DomPointInit), or a list of 1 to 4 radii.

Exceptions

RangeErrorException
The number of radii is not between 1 and 4, or a radius is negative.

See also

Pushes a copy of the drawing state on the stack (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-save).

public void Save()

Scale(double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-scale

public void Scale(double x, double y)

SetLineDash(IReadOnlyList<double>)

CanvasRenderingContext2DBase.cs

Sets the dash list of the lines (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-setlinedash): a list with a negative or non-finite value is ignored, a list with an odd number of values is repeated.

public void SetLineDash(IReadOnlyList<double> segments)

SetTransform overloads

SetTransform(DomMatrix2DInit?)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-settransform-matrix

public void SetTransform(DomMatrix2DInit? transform = null)
Parameters
transform DomMatrix2DInit?
Exceptions
TypeErrorException
The members of the dictionary are inconsistent.
See also

SetTransform(double, double, double, double, double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-settransform

public void SetTransform(double a, double b, double c, double d, double e, double f)
  • Experimental (WEBPLATEXP0025)

Shapes a text with the current font and text styles: the returned CanvasShapedText gives its glyph runs and clusters, drawn later by CanvasRenderingContext2DBase.FillGlyphRuns and CanvasRenderingContext2DBase.StrokeGlyphRuns with the font, the text styles, the direction, the alignment and the baseline of the context at this time.

[Experimental("WEBPLATEXP0025", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public CanvasShapedText ShapeText(string text)

Stroke overloads

Strokes the current default path with the stroke style and the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-stroke).

public void Stroke()

Strokes a path with the stroke style and the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-stroke).

public void Stroke(Path2D path)

StrokeGlyphRun(CanvasGlyphRun, double, double)

CanvasRenderingContext2DBase.TextClusters.cs
  • Experimental (WEBPLATEXP0025)

Strokes a glyph run of a shaped text with the stroke style and the line styles, the alignment point of the shaped text at (x, y).

[Experimental("WEBPLATEXP0025", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void StrokeGlyphRun(CanvasGlyphRun glyphRun, double x, double y)

Parameters

glyphRun CanvasGlyphRun
The glyph run, returned by CanvasShapedText.GlyphRuns or CanvasShapedText.GlyphClusters.
x double
The x coordinate of the alignment point of the shaped text.
y double
The y coordinate of the baseline of the shaped text.

See also

StrokeGlyphRuns(IReadOnlyList<CanvasGlyphRun>, double, double)

CanvasRenderingContext2DBase.TextClusters.cs
  • Experimental (WEBPLATEXP0025)

Strokes glyph runs of shaped texts with the stroke style and the line styles, the alignment point of each shaped text at (x, y).

[Experimental("WEBPLATEXP0025", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void StrokeGlyphRuns(IReadOnlyList<CanvasGlyphRun> glyphRuns, double x, double y)

Parameters

glyphRuns IReadOnlyList<CanvasGlyphRun>
The glyph runs, returned by CanvasShapedText.GlyphRuns or CanvasShapedText.GlyphClusters.
x double
The x coordinate of the alignment point of the shaped texts.
y double
The y coordinate of the baseline of the shaped texts.

See also

StrokeRect(double, double, double, double)

CanvasRenderingContext2DBase.cs

Strokes the outline of a rectangle with the stroke style and the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-strokerect).

public void StrokeRect(double x, double y, double w, double h)

StrokeText(string, double, double, double?)

CanvasRenderingContext2DBase.Text.cs

Strokes a text at a point with the stroke style and the line styles (https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-stroketext).

public void StrokeText(string text, double x, double y, double? maxWidth = null)

Parameters

text string
The text.
x double
The x coordinate of the alignment point.
y double
The y coordinate of the baseline.
maxWidth double?
The maximum width: a wider text is compressed horizontally; nothing is drawn when it is not positive.

See also

StrokeTextCluster(TextCluster, double, double, TextClusterOptions?)

CanvasRenderingContext2DBase.TextClusters.cs
  • Experimental (WEBPLATEXP0024)

Strokes a cluster of a measured text (https://github.com/whatwg/html/pull/11000) with the stroke style and the line styles: see CanvasRenderingContext2DBase.FillTextCluster.

[Experimental("WEBPLATEXP0024", UrlFormat = "https://github.com/meziantou/Meziantou.Framework/blob/main/src/Meziantou.Framework.WebPlatform/docs/experimental-apis.md#{0}")]
public void StrokeTextCluster(TextCluster textCluster, double x, double y, TextClusterOptions? options = null)

Parameters

textCluster TextCluster
The cluster, returned by TextMetrics.GetTextClusters.
x double
The x coordinate the position of the cluster is relative to.
y double
The y coordinate the position of the cluster is relative to.
options TextClusterOptions?
The alignment, the baseline and the position (x, y) that replace the ones of the cluster.

See also

Transform(double, double, double, double, double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-transform

public void Transform(double a, double b, double c, double d, double e, double f)

Translate(double, double)

CanvasRenderingContext2DBase.cs

https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-translate

public void Translate(double x, double y)