CanvasRenderingContext2D class
The interface, part of the Canvas API, provides the 2D rendering
context for the drawing surface of a <canvas>
element. It is
used for drawing shapes, text, images, and other objects.
See the interface's properties and methods in the sidebar and
below. The Canvas tutorial has more explanation, examples, and
resources, as well.
- Implemented types
- Available extensions
- PropsCanvasCompositing
- PropsCanvasDrawImage
- PropsCanvasDrawPath
- PropsCanvasFillStrokeStyles
- PropsCanvasFilters
- PropsCanvasImageData
- PropsCanvasImageSmoothing
- PropsCanvasPath
- PropsCanvasPathDrawingStyles
- PropsCanvasRect
- PropsCanvasRenderingContext2D
- PropsCanvasShadowStyles
- PropsCanvasState
- PropsCanvasText
- PropsCanvasTextDrawingStyles
- PropsCanvasTransform
- PropsCanvasUserInterface
- Annotations
-
- @JS()
- @staticInterop
Constructors
- CanvasRenderingContext2D()
-
factory
Properties
- canvas → HTMLCanvasElement
-
Available on CanvasRenderingContext2D, provided by the PropsCanvasRenderingContext2D extension
no setter - direction ↔ CanvasDirection
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - fillStyle ↔ dynamic
-
Available on CanvasFillStrokeStyles, provided by the PropsCanvasFillStrokeStyles extension
getter/setter pair - filter ↔ String
-
Available on CanvasFilters, provided by the PropsCanvasFilters extension
getter/setter pair - font ↔ String
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - fontKerning ↔ CanvasFontKerning
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - fontStretch ↔ CanvasFontStretch
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - fontVariantCaps ↔ CanvasFontVariantCaps
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - globalAlpha ↔ dynamic
-
Available on CanvasCompositing, provided by the PropsCanvasCompositing extension
getter/setter pair - globalCompositeOperation ↔ String
-
Available on CanvasCompositing, provided by the PropsCanvasCompositing extension
getter/setter pair - hashCode → int
-
The hash code for this object.
no setterinherited
- imageSmoothingEnabled ↔ bool
-
Available on CanvasImageSmoothing, provided by the PropsCanvasImageSmoothing extension
getter/setter pair - imageSmoothingQuality ↔ ImageSmoothingQuality
-
Available on CanvasImageSmoothing, provided by the PropsCanvasImageSmoothing extension
getter/setter pair - letterSpacing ↔ String
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - lineCap ↔ CanvasLineCap
-
Available on CanvasPathDrawingStyles, provided by the PropsCanvasPathDrawingStyles extension
getter/setter pair - lineDashOffset ↔ dynamic
-
Available on CanvasPathDrawingStyles, provided by the PropsCanvasPathDrawingStyles extension
getter/setter pair - lineJoin ↔ CanvasLineJoin
-
Available on CanvasPathDrawingStyles, provided by the PropsCanvasPathDrawingStyles extension
getter/setter pair - lineWidth ↔ dynamic
-
Available on CanvasPathDrawingStyles, provided by the PropsCanvasPathDrawingStyles extension
getter/setter pair - miterLimit ↔ dynamic
-
Available on CanvasPathDrawingStyles, provided by the PropsCanvasPathDrawingStyles extension
getter/setter pair - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- shadowBlur ↔ dynamic
-
Available on CanvasShadowStyles, provided by the PropsCanvasShadowStyles extension
getter/setter pair - shadowColor ↔ String
-
Available on CanvasShadowStyles, provided by the PropsCanvasShadowStyles extension
getter/setter pair - shadowOffsetX ↔ dynamic
-
Available on CanvasShadowStyles, provided by the PropsCanvasShadowStyles extension
getter/setter pair - shadowOffsetY ↔ dynamic
-
Available on CanvasShadowStyles, provided by the PropsCanvasShadowStyles extension
getter/setter pair - strokeStyle ↔ dynamic
-
Available on CanvasFillStrokeStyles, provided by the PropsCanvasFillStrokeStyles extension
getter/setter pair - textAlign ↔ CanvasTextAlign
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - textBaseline ↔ CanvasTextBaseline
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - textRendering ↔ CanvasTextRendering
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair - wordSpacing ↔ String
-
Available on CanvasTextDrawingStyles, provided by the PropsCanvasTextDrawingStyles extension
getter/setter pair
Methods
-
arc(
dynamic x, dynamic y, dynamic radius, dynamic startAngle, dynamic endAngle, [bool? counterclockwise = false]) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
arcTo(
dynamic x1, dynamic y1, dynamic x2, dynamic y2, dynamic radius) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
beginPath(
) → void -
Available on CanvasDrawPath, provided by the PropsCanvasDrawPath extension
-
bezierCurveTo(
dynamic cp1x, dynamic cp1y, dynamic cp2x, dynamic cp2y, dynamic x, dynamic y) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
clearRect(
dynamic x, dynamic y, dynamic w, dynamic h) → void -
Available on CanvasRect, provided by the PropsCanvasRect extension
-
clip(
[Path2D? path, CanvasFillRule? fillRule = CanvasFillRule.nonzero]) → void -
Available on CanvasDrawPath, provided by the PropsCanvasDrawPath extension
-
closePath(
) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
createConicGradient(
double startAngle, double x, double y) → CanvasGradient -
Available on CanvasFillStrokeStyles, provided by the PropsCanvasFillStrokeStyles extension
-
createImageData(
[int? sw, int? sh, ImageDataSettings? settings]) → ImageData -
Available on CanvasImageData, provided by the PropsCanvasImageData extension
-
createLinearGradient(
double x0, double y0, double x1, double y1) → CanvasGradient -
Available on CanvasFillStrokeStyles, provided by the PropsCanvasFillStrokeStyles extension
-
createPattern(
dynamic image, String repetition) → CanvasPattern? -
Available on CanvasFillStrokeStyles, provided by the PropsCanvasFillStrokeStyles extension
-
createRadialGradient(
double x0, double y0, double r0, double x1, double y1, double r1) → CanvasGradient -
Available on CanvasFillStrokeStyles, provided by the PropsCanvasFillStrokeStyles extension
-
drawFocusIfNeeded(
[Path2D? path, Element? element]) → void -
Available on CanvasUserInterface, provided by the PropsCanvasUserInterface extension
-
drawImage(
dynamic image, dynamic sx, [dynamic sy, dynamic sw, dynamic sh, dynamic dx, dynamic dy, dynamic dw, dynamic dh]) → void -
Available on CanvasDrawImage, provided by the PropsCanvasDrawImage extension
-
ellipse(
dynamic x, dynamic y, dynamic radiusX, dynamic radiusY, dynamic rotation, dynamic startAngle, dynamic endAngle, [bool? counterclockwise = false]) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
fill(
[Path2D? path, CanvasFillRule? fillRule = CanvasFillRule.nonzero]) → void -
Available on CanvasDrawPath, provided by the PropsCanvasDrawPath extension
-
fillRect(
dynamic x, dynamic y, dynamic w, dynamic h) → void -
Available on CanvasRect, provided by the PropsCanvasRect extension
-
fillText(
String text, dynamic x, dynamic y, [dynamic maxWidth]) → void -
Available on CanvasText, provided by the PropsCanvasText extension
-
getContextAttributes(
) → CanvasRenderingContext2DSettings -
Available on CanvasRenderingContext2D, provided by the PropsCanvasRenderingContext2D extension
-
getImageData(
int sx, int sy, int sw, int sh, [ImageDataSettings? settings]) → ImageData -
Available on CanvasImageData, provided by the PropsCanvasImageData extension
-
getLineDash(
) → Iterable -
Available on CanvasPathDrawingStyles, provided by the PropsCanvasPathDrawingStyles extension
-
getTransform(
) → DOMMatrix -
Available on CanvasTransform, provided by the PropsCanvasTransform extension
-
isContextLost(
) → bool -
Available on CanvasState, provided by the PropsCanvasState extension
-
isPointInPath(
Path2D path, dynamic x, [dynamic y, CanvasFillRule? fillRule = CanvasFillRule.nonzero]) → bool -
Available on CanvasDrawPath, provided by the PropsCanvasDrawPath extension
-
isPointInStroke(
Path2D path, [dynamic x, dynamic y]) → bool -
Available on CanvasDrawPath, provided by the PropsCanvasDrawPath extension
-
lineTo(
dynamic x, dynamic y) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
measureText(
String text) → TextMetrics -
Available on CanvasText, provided by the PropsCanvasText extension
-
moveTo(
dynamic x, dynamic y) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
putImageData(
ImageData imagedata, int dx, [int? dy, int? dirtyX, int? dirtyY, int? dirtyWidth, int? dirtyHeight]) → void -
Available on CanvasImageData, provided by the PropsCanvasImageData extension
-
quadraticCurveTo(
dynamic cpx, dynamic cpy, dynamic x, dynamic y) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
rect(
dynamic x, dynamic y, dynamic w, dynamic h) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
reset(
) → void -
Available on CanvasState, provided by the PropsCanvasState extension
-
resetTransform(
) → void -
Available on CanvasTransform, provided by the PropsCanvasTransform extension
-
restore(
) → void -
Available on CanvasState, provided by the PropsCanvasState extension
-
rotate(
dynamic angle) → void -
Available on CanvasTransform, provided by the PropsCanvasTransform extension
-
roundRect(
dynamic x, dynamic y, dynamic w, dynamic h, [dynamic radii = 0]) → void -
Available on CanvasPath, provided by the PropsCanvasPath extension
-
save(
) → void -
Available on CanvasState, provided by the PropsCanvasState extension
-
scale(
dynamic x, dynamic y) → void -
Available on CanvasTransform, provided by the PropsCanvasTransform extension
-
scrollPathIntoView(
[Path2D? path]) → void -
Available on CanvasUserInterface, provided by the PropsCanvasUserInterface extension
-
setLineDash(
Iterable segments) → void -
Available on CanvasPathDrawingStyles, provided by the PropsCanvasPathDrawingStyles extension
-
setTransform(
[dynamic a, dynamic b, dynamic c, dynamic d, dynamic e, dynamic f]) → void -
Available on CanvasTransform, provided by the PropsCanvasTransform extension
-
stroke(
[Path2D? path]) → void -
Available on CanvasDrawPath, provided by the PropsCanvasDrawPath extension
-
strokeRect(
dynamic x, dynamic y, dynamic w, dynamic h) → void -
Available on CanvasRect, provided by the PropsCanvasRect extension
-
strokeText(
String text, dynamic x, dynamic y, [dynamic maxWidth]) → void -
Available on CanvasText, provided by the PropsCanvasText extension
-
toString(
) → String -
A string representation of this object.
inherited
-
transform(
dynamic a, dynamic b, dynamic c, dynamic d, dynamic e, dynamic f) → void -
Available on CanvasTransform, provided by the PropsCanvasTransform extension
-
translate(
dynamic x, dynamic y) → void -
Available on CanvasTransform, provided by the PropsCanvasTransform extension
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited