ICanvasRenderingContext2D class

ICanvasRenderingContext2D class

The ICanvasRenderingContext2D interface is used for drawing rectangles, text, images and other objects onto the canvas element. It provides the 2D rendering context for the drawing surface of a canvas element.

The ICanvasRenderingContext2D type exposes the following members:

Properties

PropertyDescription
canvasA read-only back-reference to the HTMLCanvasElement. Might be null if it is not associated with a canvas element.
global_alphaAlpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque).
global_composite_operationWith globalAlpha applied this sets how shapes and images are drawn onto the existing bitmap. Default: (source-over)
stroke_styleColor or style to use for the lines around shapes. Default: (black).
fill_styleColor or style to use inside shapes. Default: (black).
image_smoothing_enabledImage smoothing mode; if disabled, images will not be smoothed if scaled.
shadow_offset_xHorizontal distance the shadow will be offset. Default 0.
shadow_offset_yVertical distance the shadow will be offset. Default 0.
shadow_blurSpecifies the blurring effect. Default 0
shadow_colorColor of the shadow. Default fully-transparent black.
line_widthWidth of lines. Default 1.0
line_capType of endings on the end of lines. Possible values: butt (default), round, square.
line_joinDefines the type of corners where two lines meet. Possible values: round, bevel, miter (default).
miter_limitMiter limit ratio. Default 10.
line_dash_offsetSpecifies where to start a dash array on a line.
fontFont setting. Default value 10px sans-serif
text_alignText alignment setting. Possible values: start (default), end, left, right or center.
text_baselineBaseline alignment setting. Possible values: top, hanging, middle, alphabetic (default), ideographic, bottom.

Methods

MethodDescription
create_patternCreates a pattern using the specified image (a CanvasImageSource).
It repeats the source in the directions specified by the repetition argument.
create_patternCreates a pattern using the specified image (a CanvasImageSource).
It repeats the source in the directions specified by the repetition argument.
fillFills the subpaths with the current fill style and default algorithm CanvasFillRule.Nonzero.
fillFills the subpaths with the current fill style.
fillFills the subpaths with the current fill style and default algorithm CanvasFillRule.Nonzero.
fillFills the subpaths with the current fill style.
strokeStrokes the subpaths with the current stroke style.
strokeStrokes the subpaths with the current stroke style.
clipCreates a new clipping region by calculating the intersection of the current clipping region and the area described by the path, using the non-zero winding number rule.
Open subpaths must be implicitly closed when computing the clipping region, without affecting the actual subpaths.
The new clipping region replaces the current clipping region.
clipCreates a new clipping region by calculating the intersection of the current clipping region and the area described by the path, using the non-zero winding number rule.
Open subpaths must be implicitly closed when computing the clipping region, without affecting the actual subpaths.
The new clipping region replaces the current clipping region.
clipCreates a new clipping region by calculating the intersection of the current clipping region and the area described by the path, using the non-zero winding number rule.
Open subpaths must be implicitly closed when computing the clipping region, without affecting the actual subpaths.
The new clipping region replaces the current clipping region.
is_point_in_pathReports whether or not the specified point is contained in the current path.
is_point_in_pathReports whether or not the specified point is contained in the current path.
is_point_in_pathReports whether or not the specified point is contained in the current path.
is_point_in_pathReports whether or not the specified point is contained in the current path.
is_point_in_strokeReports whether or not the specified point is inside the area contained by the stroking of a path.
is_point_in_strokeReports whether or not the specified point is inside the area contained by the stroking of a path.
fill_textDraws (fills) a given text at the given (x,y) position.
fill_textDraws (fills) a given text at the given (x,y) position.
stroke_textDraws (strokes) a given text at the given (x, y) position.
stroke_text
draw_imageDraws the specified image.
draw_imageDraws the specified image.
draw_imageDraws the specified image.
draw_imageDraws the specified image.
draw_imageDraws the specified image.
draw_imageDraws the specified image.
create_image_dataCreates a new, blank ImageData object with the specified dimensions.
All of the pixels in the new object are transparent black.
create_image_dataCreates a new, blank ImageData object with the specified dimensions.
All of the pixels in the new object are transparent black.
put_image_dataPaints data from the given ImageData object onto the bitmap.
If a dirty rectangle is provided, only the pixels from that rectangle are painted.
This method is not affected by the canvas transformation matrix.
put_image_dataPaints data from the given ImageData object onto the bitmap.
If a dirty rectangle is provided, only the pixels from that rectangle are painted.
This method is not affected by the canvas transformation matrix.
arc
arc
ellipse
ellipse
saveSaves the current drawing style state using a stack so you can revert any change you make to it using restore().
restoreRestores the drawing style state to the last element on the ‘state stack’ saved by save().
scaleAdds a scaling transformation to the canvas units by x horizontally and by y vertically.
rotateAdds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.
translateAdds a translation transformation by moving the canvas and its origin x horzontally and y vertically on the grid.
transformMultiplies the current transformation matrix with the matrix described by its arguments.
set_transformResets the current transform to the identity matrix, and then invokes the transform() method with the same arguments.
reset_transformResets the current transform by the identity matrix.
create_linear_gradientCreates a linear gradient along the line given by the coordinates represented by the parameters.
create_radial_gradientCreates a radial gradient given by the coordinates of the two circles represented by the parameters.
clear_rectSets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black, erasing any previously drawn content.
fill_rectDraws a filled rectangle at (x, y) position whose size is determined by width and height.
stroke_rectPaints a rectangle which has a starting point at (x, y) and has a w width and an h height onto the canvas, using the current stroke style.
begin_pathStarts a new path by emptying the list of sub-paths. Call this method when you want to create a new path.
draw_focus_if_neededIf a given element is focused, this method draws a focus ring around the current path.
measure_textReturns a TextMetrics object.
remove_hit_regionRemoves the hit region with the specified id from the canvas.
clear_hit_regionsRemoves all hit regions from the canvas.
get_image_dataReturns an ImageData object representing the underlying pixel data for the area of the canvas denoted by the rectangle which starts at (sx, sy) and has an sw width and sh height.
This method is not affected by the canvas transformation matrix.
set_line_dashSets the current line dash pattern.
get_line_dashReturns the current line dash pattern array containing an even number of non-negative numbers.
close_path
move_to
line_to
quadratic_curve_to
bezier_curve_to
arc_to
rect

See Also