Interface CanvasRenderingContext2D
interface CanvasRenderingContext2D {
canvas: HTMLCanvasElement;
direction: CanvasDirection;
fillStyle: string | CanvasGradient | CanvasPattern;
filter: string;
font: string;
fontKerning: CanvasFontKerning;
fontStretch: CanvasFontStretch;
fontVariantCaps: CanvasFontVariantCaps;
globalAlpha: number;
globalCompositeOperation: GlobalCompositeOperation;
imageSmoothingEnabled: boolean;
imageSmoothingQuality: ImageSmoothingQuality;
letterSpacing: string;
lineCap: CanvasLineCap;
lineDashOffset: number;
lineJoin: CanvasLineJoin;
lineWidth: number;
miterLimit: number;
shadowBlur: number;
shadowColor: string;
shadowOffsetX: number;
shadowOffsetY: number;
strokeStyle: string | CanvasGradient | CanvasPattern;
textAlign: CanvasTextAlign;
textBaseline: CanvasTextBaseline;
textRendering: CanvasTextRendering;
wordSpacing: string;
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
beginPath(): void;
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
clearRect(x: number, y: number, w: number, h: number): void;
clip(fillRule?: CanvasFillRule): void;
clip(path: Path2D, fillRule?: CanvasFillRule): void;
closePath(): void;
createConicGradient(startAngle: number, x: number, y: number): CanvasGradient;
createImageData(sw: number, sh: number, settings?: ImageDataSettings): ImageData;
createImageData(imagedata: ImageData): ImageData;
createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient;
createPattern(image: CanvasImageSourceWebCodecs, repetition: string): CanvasPattern;
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient;
drawFocusIfNeeded(element: Element): void;
drawFocusIfNeeded(path: Path2D, element: Element): void;
drawImage(image: CanvasImageSourceWebCodecs, dx: number, dy: number): void;
drawImage(image: CanvasImageSourceWebCodecs, dx: number, dy: number, dw: number, dh: number): void;
drawImage(image: CanvasImageSourceWebCodecs, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
fill(fillRule?: CanvasFillRule): void;
fill(path: Path2D, fillRule?: CanvasFillRule): void;
fillRect(x: number, y: number, w: number, h: number): void;
fillText(text: string, x: number, y: number, maxWidth?: number): void;
getContextAttributes(): CanvasRenderingContext2DSettings;
getImageData(sx: number, sy: number, sw: number, sh: number, settings?: ImageDataSettings): ImageData;
getLineDash(): number[];
getTransform(): DOMMatrix;
isContextLost(): boolean;
isPointInPath(x: number, y: number, fillRule?: CanvasFillRule): boolean;
isPointInPath(path: Path2D, x: number, y: number, fillRule?: CanvasFillRule): boolean;
isPointInStroke(x: number, y: number): boolean;
isPointInStroke(path: Path2D, x: number, y: number): boolean;
lineTo(x: number, y: number): void;
measureText(text: string): TextMetrics;
moveTo(x: number, y: number): void;
putImageData(imagedata: ImageData, dx: number, dy: number): void;
putImageData(imagedata: ImageData, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number): void;
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
rect(x: number, y: number, w: number, h: number): void;
reset(): void;
resetTransform(): void;
restore(): void;
rotate(angle: number): void;
roundRect(x: number, y: number, w: number, h: number, radii?: number | DOMPointInit | (number | DOMPointInit)[]): void;
roundRect(x: number, y: number, w: number, h: number, radii?: number | DOMPointInit | Iterable<number | DOMPointInit, any, any>): void;
save(): void;
scale(x: number, y: number): void;
setLineDash(segments: number[]): void;
setLineDash(segments: Iterable<number, any, any>): void;
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
setTransform(transform?: DOMMatrix2DInit): void;
stroke(): void;
stroke(path: Path2D): void;
strokeRect(x: number, y: number, w: number, h: number): void;
strokeText(text: string, x: number, y: number, maxWidth?: number): void;
transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
translate(x: number, y: number): void;
}
canvas: HTMLCanvasElement;
direction: CanvasDirection;
fillStyle: string | CanvasGradient | CanvasPattern;
filter: string;
font: string;
fontKerning: CanvasFontKerning;
fontStretch: CanvasFontStretch;
fontVariantCaps: CanvasFontVariantCaps;
globalAlpha: number;
globalCompositeOperation: GlobalCompositeOperation;
imageSmoothingEnabled: boolean;
imageSmoothingQuality: ImageSmoothingQuality;
letterSpacing: string;
lineCap: CanvasLineCap;
lineDashOffset: number;
lineJoin: CanvasLineJoin;
lineWidth: number;
miterLimit: number;
shadowBlur: number;
shadowColor: string;
shadowOffsetX: number;
shadowOffsetY: number;
strokeStyle: string | CanvasGradient | CanvasPattern;
textAlign: CanvasTextAlign;
textBaseline: CanvasTextBaseline;
textRendering: CanvasTextRendering;
wordSpacing: string;
arc(x: number, y: number, radius: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
arcTo(x1: number, y1: number, x2: number, y2: number, radius: number): void;
beginPath(): void;
bezierCurveTo(cp1x: number, cp1y: number, cp2x: number, cp2y: number, x: number, y: number): void;
clearRect(x: number, y: number, w: number, h: number): void;
clip(fillRule?: CanvasFillRule): void;
clip(path: Path2D, fillRule?: CanvasFillRule): void;
closePath(): void;
createConicGradient(startAngle: number, x: number, y: number): CanvasGradient;
createImageData(sw: number, sh: number, settings?: ImageDataSettings): ImageData;
createImageData(imagedata: ImageData): ImageData;
createLinearGradient(x0: number, y0: number, x1: number, y1: number): CanvasGradient;
createPattern(image: CanvasImageSourceWebCodecs, repetition: string): CanvasPattern;
createRadialGradient(x0: number, y0: number, r0: number, x1: number, y1: number, r1: number): CanvasGradient;
drawFocusIfNeeded(element: Element): void;
drawFocusIfNeeded(path: Path2D, element: Element): void;
drawImage(image: CanvasImageSourceWebCodecs, dx: number, dy: number): void;
drawImage(image: CanvasImageSourceWebCodecs, dx: number, dy: number, dw: number, dh: number): void;
drawImage(image: CanvasImageSourceWebCodecs, sx: number, sy: number, sw: number, sh: number, dx: number, dy: number, dw: number, dh: number): void;
ellipse(x: number, y: number, radiusX: number, radiusY: number, rotation: number, startAngle: number, endAngle: number, counterclockwise?: boolean): void;
fill(fillRule?: CanvasFillRule): void;
fill(path: Path2D, fillRule?: CanvasFillRule): void;
fillRect(x: number, y: number, w: number, h: number): void;
fillText(text: string, x: number, y: number, maxWidth?: number): void;
getContextAttributes(): CanvasRenderingContext2DSettings;
getImageData(sx: number, sy: number, sw: number, sh: number, settings?: ImageDataSettings): ImageData;
getLineDash(): number[];
getTransform(): DOMMatrix;
isContextLost(): boolean;
isPointInPath(x: number, y: number, fillRule?: CanvasFillRule): boolean;
isPointInPath(path: Path2D, x: number, y: number, fillRule?: CanvasFillRule): boolean;
isPointInStroke(x: number, y: number): boolean;
isPointInStroke(path: Path2D, x: number, y: number): boolean;
lineTo(x: number, y: number): void;
measureText(text: string): TextMetrics;
moveTo(x: number, y: number): void;
putImageData(imagedata: ImageData, dx: number, dy: number): void;
putImageData(imagedata: ImageData, dx: number, dy: number, dirtyX: number, dirtyY: number, dirtyWidth: number, dirtyHeight: number): void;
quadraticCurveTo(cpx: number, cpy: number, x: number, y: number): void;
rect(x: number, y: number, w: number, h: number): void;
reset(): void;
resetTransform(): void;
restore(): void;
rotate(angle: number): void;
roundRect(x: number, y: number, w: number, h: number, radii?: number | DOMPointInit | (number | DOMPointInit)[]): void;
roundRect(x: number, y: number, w: number, h: number, radii?: number | DOMPointInit | Iterable<number | DOMPointInit, any, any>): void;
save(): void;
scale(x: number, y: number): void;
setLineDash(segments: number[]): void;
setLineDash(segments: Iterable<number, any, any>): void;
setTransform(a: number, b: number, c: number, d: number, e: number, f: number): void;
setTransform(transform?: DOMMatrix2DInit): void;
stroke(): void;
stroke(path: Path2D): void;
strokeRect(x: number, y: number, w: number, h: number): void;
strokeText(text: string, x: number, y: number, maxWidth?: number): void;
transform(a: number, b: number, c: number, d: number, e: number, f: number): void;
translate(x: number, y: number): void;
}
Hierarchy
Index
Properties
canvas
direction
fillStyle
filter
font
fontKerning
fontStretch
fontVariantCaps
globalAlpha
globalCompositeOperation
imageSmoothingEnabled
imageSmoothingQuality
letterSpacing
lineCap
lineDashOffset
lineJoin
lineWidth
miterLimit
shadowBlur
shadowColor
shadowOffsetX
shadowOffsetY
strokeStyle
textAlign
textBaseline
textRendering
wordSpacing
Methods
arc
arcTo
beginPath
bezierCurveTo
clearRect
clip
closePath
createConicGradient
createImageData
createLinearGradient
createPattern
createRadialGradient
drawFocusIfNeeded
drawImage
ellipse
fill
fillRect
fillText
getContextAttributes
getImageData
getLineDash
getTransform
isContextLost
isPointInPath
isPointInStroke
lineTo
measureText
moveTo
putImageData
quadraticCurveTo
rect
reset
resetTransform
restore
rotate
roundRect
save
scale
setLineDash
setTransform
stroke
strokeRect
strokeText
transform
translate
Properties
Readonly
canvas
direction
fillStyle
filter
filter: string
font
font: string
fontKerning
fontStretch
fontVariantCaps
globalAlpha
globalAlpha : number
globalCompositeOperation
imageSmoothingEnabled
imageSmoothingEnabled : boolean
imageSmoothingQuality
letterSpacing
letterSpacing : string
lineCap
lineDashOffset
lineDashOffset : number
lineJoin
lineWidth
lineWidth : number
miterLimit
miterLimit : number
shadowBlur
shadowBlur : number
shadowColor
shadowColor : string
shadowOffsetX
shadowOffsetX : number
shadowOffsetY
shadowOffsetY : number
strokeStyle
textAlign
textBaseline
textRendering
wordSpacing
wordSpacing : string
Methods
arc
arcTo
beginPath
bezierCurveTo
clearRect
clip
- clip(fillRule?): void
Parameters
Optional
fillRule: CanvasFillRule
Returns void
- clip(path, fillRule?): void
Parameters
- path: Path2D
Optional
fillRule: CanvasFillRule
Returns void
closePath
createConicGradient
- create
Conic (startAngle, x, y): CanvasGradientGradient Parameters
- startAngle: number
- x: number
- y: number
Returns CanvasGradient
createImageData
createLinearGradient
- create
Linear (x0, y0, x1, y1): CanvasGradientGradient Parameters
- x0: number
- y0: number
- x1: number
- y1: number
Returns CanvasGradient
createPattern
- create
Pattern (image, repetition): CanvasPattern Parameters
- image: CanvasImageSourceWebCodecs
- repetition: string
Returns CanvasPattern
createRadialGradient
- create
Radial (x0, y0, r0, x1, y1, r1): CanvasGradientGradient Parameters
- x0: number
- y0: number
- r0: number
- x1: number
- y1: number
- r1: number
Returns CanvasGradient
drawFocusIfNeeded
- draw
Focus (element): voidIf Needed Parameters
- element: Element
Returns void
- draw
Focus (path, element): voidIf Needed Returns void
drawImage
- draw
Image (image, dx, dy): void Parameters
- image: CanvasImageSourceWebCodecs
- dx: number
- dy: number
Returns void
- draw
Image (image, dx, dy, dw, dh): void Parameters
- image: CanvasImageSourceWebCodecs
- dx: number
- dy: number
- dw: number
- dh: number
Returns void
- draw
Image (image, sx, sy, sw, sh, dx, dy, dw, dh): void Parameters
- image: CanvasImageSourceWebCodecs
- sx: number
- sy: number
- sw: number
- sh: number
- dx: number
- dy: number
- dw: number
- dh: number
Returns void
ellipse
fill
- fill(fillRule?): void
Parameters
Optional
fillRule: CanvasFillRule
Returns void
- fill(path, fillRule?): void
Parameters
- path: Path2D
Optional
fillRule: CanvasFillRule
Returns void
fillRect
fillText
getContextAttributes
- get
Context (): CanvasRenderingContext2DSettingsAttributes Returns CanvasRenderingContext2DSettings
getImageData
- get
Image (sx, sy, sw, sh, settings?): ImageDataData Parameters
- sx: number
- sy: number
- sw: number
- sh: number
Optional
settings: ImageDataSettings
Returns ImageData
getLineDash
getTransform
isContextLost
isPointInPath
- is
Point (x, y, fillRule?): booleanIn Path Parameters
- x: number
- y: number
Optional
fillRule: CanvasFillRule
Returns boolean
- is
Point (path, x, y, fillRule?): booleanIn Path Parameters
- path: Path2D
- x: number
- y: number
Optional
fillRule: CanvasFillRule
Returns boolean
isPointInStroke
- is
Point (x, y): booleanIn Stroke Parameters
- x: number
- y: number
Returns boolean
- is
Point (path, x, y): booleanIn Stroke Parameters
- path: Path2D
- x: number
- y: number
Returns boolean
lineTo
measureText
- measure
Text (text): TextMetrics Parameters
- text: string
Returns TextMetrics
moveTo
putImageData
- put
Image (imagedata, dx, dy): voidData Parameters
- imagedata: ImageData
- dx: number
- dy: number
Returns void
- put
Image (imagedata, dx, dy, dirtyX, dirtyY, dirtyWidth, dirtyHeight): voidData Parameters
- imagedata: ImageData
- dx: number
- dy: number
- dirtyX: number
- dirtyY: number
- dirtyWidth: number
- dirtyHeight: number
Returns void
quadraticCurveTo
rect
reset
resetTransform
restore
rotate
roundRect
- round
Rect (x, y, w, h, radii?): void Parameters
- x: number
- y: number
- w: number
- h: number
Optional
radii: number | DOMPointInit | (number | DOMPointInit)[]
Returns void
- round
Rect (x, y, w, h, radii?): void Parameters
- x: number
- y: number
- w: number
- h: number
Optional
radii: number | DOMPointInit | Iterable<number | DOMPointInit, any, any>
Returns void
save
scale
setLineDash
- set
Line (segments): voidDash Parameters
- segments: number[]
Returns void
- set
Line (segments): voidDash Parameters
- segments: Iterable<number, any, any>
Returns void
setTransform
- set
Transform (a, b, c, d, e, f): void Parameters
- a: number
- b: number
- c: number
- d: number
- e: number
- f: number
Returns void
- set
Transform (transform?): void Parameters
Optional
transform: DOMMatrix2DInit
Returns void
stroke
- stroke(): void
Returns void
- stroke(path): void
Parameters
- path: Path2D
Returns void
MDN Reference