Path2D Class

A path that can be filled, stroked or used as a clip by the 2D contexts (https://html.spec.whatwg.org/multipage/canvas.html#path2d-objects): its subpaths are in the coordinates of the drawing operations that use it (transformed by their current transformation matrix).

public sealed class Path2D

Constructors

NameDescription
Path2D()Creates an empty path (https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d).
Path2D(object?)Creates a copy of a path, or the path of SVG path data (https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d): the commands up to the first error of the path data.

Path2D overloads

Path2D()

Path2D.cs

Creates an empty path (https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d).

public Path2D()

Path2D(object?)

Path2D.cs

Creates a copy of a path, or the path of SVG path data (https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d): the commands up to the first error of the path data.

public Path2D(object? path)
Parameters
path object?
A Path2D or a string of SVG path data.
See also

Methods

NameDescription
AddPath(Path2D, DomMatrix2DInit?)Adds the subpaths of a path, transformed by a matrix (https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d-addpath): a matrix with a non-finite component is ignored (nothing is added).
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
BezierCurveTo(double, double, double, double, double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-beziercurveto
ClosePath()https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-closepath
Ellipse(double, double, double, double, double, double, double, bool)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-ellipse
LineTo(double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-lineto
MoveTo(double, double)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-moveto
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
RoundRect(double, double, double, double, object?)https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-roundrect

AddPath(Path2D, DomMatrix2DInit?)

Path2D.cs

Adds the subpaths of a path, transformed by a matrix (https://html.spec.whatwg.org/multipage/canvas.html#dom-path2d-addpath): a matrix with a non-finite component is ignored (nothing is added).

public void AddPath(Path2D path, DomMatrix2DInit? transform = null)

Parameters

path Path2D
transform DomMatrix2DInit?

Exceptions

TypeErrorException
The members of the dictionary are inconsistent.

See also

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

Path2D.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)

Path2D.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

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

Path2D.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)

ClosePath()

Path2D.cs

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

public void ClosePath()

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

Path2D.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

LineTo(double, double)

Path2D.cs

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

public void LineTo(double x, double y)

MoveTo(double, double)

Path2D.cs

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

public void MoveTo(double x, double y)

QuadraticCurveTo(double, double, double, double)

Path2D.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)

Path2D.cs

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

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

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

Path2D.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