ICanvasRenderingContext2D Interface
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.

Namespace: Aspose.Html.Dom.Canvas
Assembly: Aspose.HTML (in Aspose.HTML.dll) Version: 21.4
Syntax
public interface ICanvasRenderingContext2D : ICanvasDrawingStyles, 
	ICanvasPathMethods

The ICanvasRenderingContext2D type exposes the following members.

Properties
  NameDescription
Public propertyCanvas
A read-only back-reference to the HTMLCanvasElement. Might be null if it is not associated with a canvas element.
Public propertyFillStyle
Color or style to use inside shapes. Default: (black).
Public propertyFont
Font setting. Default value 10px sans-serif
(Inherited from ICanvasDrawingStyles.)
Public propertyGlobalAlpha
Alpha value that is applied to shapes and images before they are composited onto the canvas. Default 1.0 (opaque).
Public propertyGlobalCompositeOperation
With globalAlpha applied this sets how shapes and images are drawn onto the existing bitmap. Default: (source-over)
Public propertyImageSmoothingEnabled
Image smoothing mode; if disabled, images will not be smoothed if scaled.
Public propertyLineCap
Type of endings on the end of lines. Possible values: butt (default), round, square.
(Inherited from ICanvasDrawingStyles.)
Public propertyLineDashOffset
Specifies where to start a dash array on a line.
(Inherited from ICanvasDrawingStyles.)
Public propertyLineJoin
Defines the type of corners where two lines meet. Possible values: round, bevel, miter (default).
(Inherited from ICanvasDrawingStyles.)
Public propertyLineWidth
Width of lines. Default 1.0
(Inherited from ICanvasDrawingStyles.)
Public propertyMiterLimit
Miter limit ratio. Default 10.
(Inherited from ICanvasDrawingStyles.)
Public propertyShadowBlur
Specifies the blurring effect. Default 0
Public propertyShadowColor
Color of the shadow. Default fully-transparent black.
Public propertyShadowOffsetX
Horizontal distance the shadow will be offset. Default 0.
Public propertyShadowOffsetY
Vertical distance the shadow will be offset. Default 0.
Public propertyStrokeStyle
Color or style to use for the lines around shapes. Default: (black).
Public propertyTextAlign
Text alignment setting. Possible values: start (default), end, left, right or center.
(Inherited from ICanvasDrawingStyles.)
Public propertyTextBaseline
Baseline alignment setting. Possible values: top, hanging, middle, alphabetic (default), ideographic, bottom.
(Inherited from ICanvasDrawingStyles.)
Methods
  NameDescription
Public methodAddHitRegion
Adds a hit region to the canvas. This allows you to make hit detection easier, lets you route events to DOM elements, and makes it possible for users to explore the canvas without seeing it.
Public methodArc(Double, Double, Double, Double, Double)
Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
(Inherited from ICanvasPathMethods.)
Public methodArc(Double, Double, Double, Double, Double, Boolean)
Adds an arc to the path which is centered at (x, y) position with radius r starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
(Inherited from ICanvasPathMethods.)
Public methodArcTo
Adds an arc to the path with the given control points and radius, connected to the previous point by a straight line.
(Inherited from ICanvasPathMethods.)
Public methodBeginPath
Starts a new path by emptying the list of sub-paths. Call this method when you want to create a new path.
Public methodBezierCurveTo
Adds a cubic Bézier curve to the path. It requires three points. The first two points are control points and the third one is the end point. The starting point is the last point in the current path, which can be changed using moveTo() before creating the Bézier curve.
(Inherited from ICanvasPathMethods.)
Public methodClearHitRegions
Removes all hit regions from the canvas.
Public methodClearRect
Sets all pixels in the rectangle defined by starting point (x, y) and size (width, height) to transparent black, erasing any previously drawn content.
Public methodClip
Creates 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.
Public methodClip(CanvasFillRule)
Creates 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.
Public methodClip(Path2D, CanvasFillRule)
Creates 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.
Public methodClosePath
Causes the point of the pen to move back to the start of the current sub-path. It tries to draw a straight line from the current point to the start. If the shape has already been closed or has only one point, this function does nothing.
(Inherited from ICanvasPathMethods.)
Public methodCreateImageData(IImageData)
Creates a new, blank ImageData object with the specified dimensions. All of the pixels in the new object are transparent black.
Public methodCreateImageData(Double, Double)
Creates a new, blank ImageData object with the specified dimensions. All of the pixels in the new object are transparent black.
Public methodCreateLinearGradient
Creates a linear gradient along the line given by the coordinates represented by the parameters.
Public methodCreatePattern(HTMLCanvasElement, String)
Creates a pattern using the specified image (a CanvasImageSource). It repeats the source in the directions specified by the repetition argument.
Public methodCreatePattern(HTMLImageElement, String)
Creates a pattern using the specified image (a CanvasImageSource). It repeats the source in the directions specified by the repetition argument.
Public methodCreateRadialGradient
Creates a radial gradient given by the coordinates of the two circles represented by the parameters.
Public methodDrawFocusIfNeeded
If a given element is focused, this method draws a focus ring around the current path.
Public methodDrawImage(HTMLCanvasElement, Double, Double)
Draws the specified image.
Public methodDrawImage(HTMLImageElement, Double, Double)
Draws the specified image.
Public methodDrawImage(HTMLCanvasElement, Double, Double, Double, Double)
Draws the specified image.
Public methodDrawImage(HTMLImageElement, Double, Double, Double, Double)
Draws the specified image.
Public methodDrawImage(HTMLCanvasElement, Double, Double, Double, Double, Double, Double, Double, Double)
Draws the specified image.
Public methodDrawImage(HTMLImageElement, Double, Double, Double, Double, Double, Double, Double, Double)
Draws the specified image.
Public methodEllipse(Double, Double, Double, Double, Double, Double, Double)
Adds an ellipse to the path which is centered at (x, y) position with the radii radiusX and radiusY starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
(Inherited from ICanvasPathMethods.)
Public methodEllipse(Double, Double, Double, Double, Double, Double, Double, Boolean)
Adds an ellipse to the path which is centered at (x, y) position with the radii radiusX and radiusY starting at startAngle and ending at endAngle going in the given direction by anticlockwise (defaulting to clockwise).
(Inherited from ICanvasPathMethods.)
Public methodFill
Fills the subpaths with the current fill style and default algorithm CanvasFillRule.Nonzero.
Public methodFill(CanvasFillRule)
Fills the subpaths with the current fill style.
Public methodFill(Path2D)
Fills the subpaths with the current fill style and default algorithm CanvasFillRule.Nonzero.
Public methodFill(Path2D, CanvasFillRule)
Fills the subpaths with the current fill style.
Public methodFillRect
Draws a filled rectangle at (x, y) position whose size is determined by width and height.
Public methodFillText(String, Double, Double)
Draws (fills) a given text at the given (x,y) position.
Public methodFillText(String, Double, Double, Double)
Draws (fills) a given text at the given (x,y) position.
Public methodGetImageData
Returns 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.
Public methodGetLineDash
Returns the current line dash pattern array containing an even number of non-negative numbers.
(Inherited from ICanvasDrawingStyles.)
Public methodIsPointInPath(Double, Double)
Reports whether or not the specified point is contained in the current path.
Public methodIsPointInPath(Double, Double, CanvasFillRule)
Reports whether or not the specified point is contained in the current path.
Public methodIsPointInPath(Path2D, Double, Double)
Reports whether or not the specified point is contained in the current path.
Public methodIsPointInPath(Path2D, Double, Double, CanvasFillRule)
Reports whether or not the specified point is contained in the current path.
Public methodIsPointInStroke(Double, Double)
Reports whether or not the specified point is inside the area contained by the stroking of a path.
Public methodIsPointInStroke(Path2D, Double, Double)
Reports whether or not the specified point is inside the area contained by the stroking of a path.
Public methodLineTo
Connects the last point in the subpath to the x, y coordinates with a straight line.
(Inherited from ICanvasPathMethods.)
Public methodMeasureText
Returns a TextMetrics object.
Public methodMoveTo
Moves the starting point of a new sub-path to the (x, y) coordinates.
(Inherited from ICanvasPathMethods.)
Public methodPutImageData(IImageData, Double, Double)
Paints 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.
Public methodPutImageData(IImageData, Double, Double, Double, Double, Double, Double)
Paints 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.
Public methodQuadraticCurveTo
Adds a quadratic Bézier curve to the current path.
(Inherited from ICanvasPathMethods.)
Public methodRect
Creates a path for a rectangle at position (x, y) with a size that is determined by width and height.
(Inherited from ICanvasPathMethods.)
Public methodRemoveHitRegion
Removes the hit region with the specified id from the canvas.
Public methodResetTransform
Resets the current transform by the identity matrix.
Public methodRestore
Restores the drawing style state to the last element on the 'state stack' saved by save().
Public methodRotate
Adds a rotation to the transformation matrix. The angle argument represents a clockwise rotation angle and is expressed in radians.
Public methodSave
Saves the current drawing style state using a stack so you can revert any change you make to it using restore().
Public methodScale
Adds a scaling transformation to the canvas units by x horizontally and by y vertically.
Public methodSetLineDash
Sets the current line dash pattern.
(Inherited from ICanvasDrawingStyles.)
Public methodSetTransform
Resets the current transform to the identity matrix, and then invokes the transform() method with the same arguments.
Public methodStroke
Strokes the subpaths with the current stroke style.
Public methodStroke(Path2D)
Strokes the subpaths with the current stroke style.
Public methodStrokeRect
Paints 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.
Public methodStrokeText(String, Double, Double)
Draws (strokes) a given text at the given (x, y) position.
Public methodStrokeText(String, Double, Double, NullableDouble)
Draws (strokes) a given text at the given (x, y) position.
Public methodTransform
Multiplies the current transformation matrix with the matrix described by its arguments.
Public methodTranslate
Adds a translation transformation by moving the canvas and its origin x horzontally and y vertically on the grid.
See Also