Skip to main content
Version: 3.5

Canvas

Namespace: Wisej.Web

Assembly: Wisej.Framework (3.5.0.0)

Represents the HTML5 canvas element.

public class Canvas : Control, IWisejHandler

Constructors

Instance memberCanvas()

Initializes a new instance of the Canvas class.

Properties

Instance memberBorderStyle

BorderStyle: Indicates the border style for the control. (Default: None)

Instance memberFillStyle

Object: Sets or returns the color, gradient, or pattern used to fill the drawing.

Instance memberGlobalAlpha

Single: Sets or returns the current alpha or transparency value of the drawing.

Instance memberGlobalCompositeOperation

CanvasCompositeOperation: Sets or returns how a new image are drawn onto an existing image.

Instance memberLineCap

CanvasLineCap: Sets or returns the style of the end caps for a line.

Instance memberLineDashOffset

Single: Sets or returns the type of corner created, when two lines meet.

Instance memberLineJoin

CanvasLineJoin: Sets or returns the type of corner created, when two lines meet.

Instance memberLineWidth

Int32: Sets or returns the current line width, in pixels.

Instance memberLiveUpdate

Boolean: Turns live update mode on or off. When live update is on, all canvas calls are pushed to the client immediately, when is off (default) the control updates the client at the end of the request.

Instance memberMiterLimit

Int32: Sets or returns the maximum miter length.

Instance memberShadowBlur

Int32: Sets or returns the blur level for shadows.

Instance memberShadowColor

Color: Sets or returns the color to use for shadows.

Instance memberShadowOffsetX

Int32: Sets or returns the horizontal distance of the shadow from the shape.

Instance memberShadowOffsetY

Int32: Sets or returns the vertical distance of the shadow from the shape.

Instance memberStrokeStyle

Object: Sets or returns the color, gradient, or pattern used for strokes.

Instance memberTextAlign

CanvasTextAlign: Sets or returns the current alignment for text content, according to the anchor point.

Instance memberTextBaseline

CanvasTextBaseline: Sets or returns the current text baseline used when drawing text.

Instance memberTextFont

Font: Sets or returns the current font properties for text content on the canvas.

Methods

Instance memberArc(x, y, radius, startAngle, endAngle, counterClockwise)

Creates an arc/curve (used to create circles, or parts of circles).

ParameterTypeDescription
xInt32The x-coordinate of the center of the circle.
yInt32The y-coordinate of the center of the circle.
radiusInt32The radius of the circle.
startAngleSingleThe starting angle, in degrees.
endAngleSingleThe ending angle, in degrees.
counterClockwise optionalBooleanSpecifies whether the drawing should be counterclockwise or clockwise. Default is false.

Instance memberArc(location, radius, startAngle, endAngle, counterClockwise)

Creates an arc/curve (used to create circles, or parts of circles).

ParameterTypeDescription
locationPointThe x-coordinate and y-coordinate of the center of the circle.
radiusInt32The radius of the circle.
startAngleSingleThe starting angle, in degrees.
endAngleSingleThe ending angle, in degrees.
counterClockwise optionalBooleanSpecifies whether the drawing should be counterclockwise or clockwise. Default is false.

Instance memberArcTo(x1, y1, x2, y2, radius)

Creates an arc/curve between two tangents on the canvas.

ParameterTypeDescription
x1Int32The x-coordinate of the first tangent.
y1Int32The y-coordinate of the first tangent.
x2Int32The x-coordinate of the second tangent.
y2Int32The y-coordinate of the second tangent.
radiusInt32The radius of the arc

Instance memberArcTo(location1, location2, radius)

Creates an arc/curve between two tangents on the canvas.

ParameterTypeDescription
location1PointThe x-coordinate and y-coordinate of the first tangent.
location2PointThe x-coordinate and y-coordinate of the second tangent.
radiusInt32The radius of the arc

Instance memberBeginPath()

begins a path, or resets the current path.

Instance memberBezierCurveTo(cp1x, cp1y, cp2x, cp2y, x, y)

Adds a point to the current path by using the specified control points that represent a cubic Bézier curve.

ParameterTypeDescription
cp1xInt32The x-coordinate of the first Bézier control point.
cp1yInt32The y-coordinate of the first Bézier control point.
cp2xInt32The x-coordinate of the second Bézier control point.
cp2yInt32The y-coordinate of the second Bézier control point.
xInt32The x-coordinate of the ending point.
yInt32The y-coordinate of the ending point.

A cubic bezier curve requires three points. The first two points are control points that are used in the cubic Bézier calculation and the last point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point.

Instance memberClearRect(rect)

Clears the specified pixels within a given rectangle.

ParameterTypeDescription
rectRectangleRectangle's coordinates and size.

Instance memberClearRect(x, y, width, height)

Clears the specified pixels within a given rectangle.

ParameterTypeDescription
xInt32The x-coordinate of the upper-left corner of the rectangle.
yInt32The y-coordinate of the upper-left corner of the rectangle.
widthInt32The width of the rectangle, in pixels.
heightInt32The height of the rectangle, in pixels.

Instance memberClip()

Clips a region of any shape and size from the original canvas.

Once a region is clipped, all future drawing will be limited to the clipped region (no access to other regions on the canvas). You can however save the current canvas region using the save() method before using the clip() method, and restore it (with the restore() method) any time in the future.

Instance memberClosePath()

Creates a path from the current point back to the starting point.

Instance memberCreateLinearGradient(x0, y0, x1, y1, colorStops)

Creates a linear gradient object. The gradient can be used to fill rectangles, circles, lines, text, etc.

ParameterTypeDescription
x0Int32The x-coordinate of the start point of the gradient.
y0Int32The y-coordinate of the start point of the gradient.
x1Int32The x-coordinate of the end point of the gradient.
y1Int32The y-coordinate of the end point of the gradient.
colorStopsObject[]Array of color stops. Each element must define a stop value between 0.0 and 1.0 and a color value.

Returns: Object.

Instance memberCreatePattern(image, repeat)

Repeats the specified element in the specified direction. The repeated element can be used to draw/fill rectangles, circles, lines etc.

ParameterTypeDescription
imageImageSpecifies the image of the pattern to use.
repeatCanvasRepeatPatternSpecifies the repeat pattern.

Returns: Object.

Instance memberCreatePattern(imageSource, repeat)

Repeats the specified element in the specified direction. The repeated element can be used to draw/fill rectangles, circles, lines etc.

ParameterTypeDescription
imageSourceStringSpecifies the source of the image of the pattern to use.
repeatCanvasRepeatPatternSpecifies the repeat pattern.

Returns: Object.

Instance memberCreateRadialGradient(x0, y0, r0, x1, y1, r1, colorStops)

Creates a linear gradient object. The gradient can be used to fill rectangles, circles, lines, text, etc.

ParameterTypeDescription
x0Int32The x-coordinate of the start point of the gradient.
y0Int32The y-coordinate of the start point of the gradient.
r0SingleThe radius of the starting circle.
x1Int32The x-coordinate of the end point of the gradient.
y1Int32The y-coordinate of the end point of the gradient.
r1SingleThe radius of the ending circle.
colorStopsObject[]Array of color stops. Each element must define a stop value between 0.0 and 1.0 and a color value.

Returns: Object.

Instance memberDrawImage(image, x, y)

Draws an image onto the canvas.

ParameterTypeDescription
imageImageSpecifies the image to draw.
xInt32The x-coordinate where to place the image on the canvas.
yInt32The y-coordinate where to place the image on the canvas.

Instance memberDrawImage(image, location)

Draws an image onto the canvas.

ParameterTypeDescription
imageImageSpecifies the image to draw.
locationPointThe x-coordinate and y-coordinate where to place the image on the canvas.

Instance memberDrawImage(image, x, y, width, height)

Draws an image onto the canvas.

ParameterTypeDescription
imageImageSpecifies the image to draw.
xInt32The x-coordinate where to place the image on the canvas.
yInt32The y-coordinate where to place the image on the canvas.
widthInt32The width of the image to use (stretch or reduce the image).
heightInt32The height of the image to use (stretch or reduce the image).

Instance memberDrawImage(image, rect)

Draws an image onto the canvas.

ParameterTypeDescription
imageImageSpecifies the image to draw.
rectRectangleThe coordinates and size of the image to place on the canvas.

Instance memberDrawImage(image, clipX, clipY, clipWidth, clipHeight, x, y, width, height)

Draws an image onto the canvas.

ParameterTypeDescription
imageImageSpecifies the image to draw.
clipXInt32The x-coordinate where to start clipping.
clipYInt32The y-coordinate where to start clipping.
clipWidthInt32The width of the clipped image.
clipHeightInt32The height of the clipped image.
xInt32The x coordinate where to place the image on the canvas.
yInt32The y coordinate where to place the image on the canvas.
widthInt32The width of the image to use (stretch or reduce the image).
heightInt32The height of the image to use (stretch or reduce the image).

Instance memberDrawImage(image, clipRect, imageRect)

Draws an image onto the canvas.

ParameterTypeDescription
imageImageSpecifies the image to draw.
clipRectRectangleThe clip rectangle.
imageRectRectangleThe size and location of the image to place on the canvas.

Instance memberDrawImage(imageSource, x, y)

Draws an image onto the canvas.

ParameterTypeDescription
imageSourceStringSpecifies the image to draw.
xInt32The x-coordinate where to place the image on the canvas.
yInt32The y-coordinate where to place the image on the canvas.

Instance memberDrawImage(imageSource, location)

Draws an image onto the canvas.

ParameterTypeDescription
imageSourceStringSpecifies the image to draw.
locationPointThe x-coordinate and y-coordinate where to place the image on the canvas.

Instance memberDrawImage(imageSource, x, y, width, height)

Draws an image onto the canvas.

ParameterTypeDescription
imageSourceStringSpecifies the image to draw.
xInt32The x coordinate where to place the image on the canvas.
yInt32The y coordinate where to place the image on the canvas.
widthInt32The width of the image to use (stretch or reduce the image).
heightInt32The height of the image to use (stretch or reduce the image).

Instance memberDrawImage(imageSource, rect)

Draws an image onto the canvas.

ParameterTypeDescription
imageSourceStringSpecifies the image to draw.
rectRectangleThe coordinates and size of the image to place on the canvas.

Instance memberDrawImage(imageSource, clipX, clipY, clipWidth, clipHeight, x, y, width, height)

Draws an image onto the canvas.

ParameterTypeDescription
imageSourceStringSpecifies the image to draw.
clipXInt32The x coordinate where to start clipping.
clipYInt32The y coordinate where to start clipping.
clipWidthInt32The width of the clipped image.
clipHeightInt32The height of the clipped image.
xInt32The x coordinate where to place the image on the canvas.
yInt32The y coordinate where to place the image on the canvas.
widthInt32The width of the image to use (stretch or reduce the image).
heightInt32The height of the image to use (stretch or reduce the image).

Instance memberDrawImage(imageSource, clipRect, imageRect)

Draws an image onto the canvas.

ParameterTypeDescription
imageSourceStringSpecifies the image to draw.
clipRectRectangleThe clip rectangle.
imageRectRectangleThe size and location of the image to place on the canvas.

Instance memberFill()

Fills the current drawing (path.)

Instance memberFillRect(rect)

Draws a "filled" rectangle. The default color of the fill is black.

ParameterTypeDescription
rectRectangleRectangle's coordinates and size.

Instance memberFillRect(x, y, width, height)

Draws a "filled" rectangle. The default color of the fill is black.

ParameterTypeDescription
xInt32The x-coordinate of the upper-left corner of the rectangle.
yInt32The y-coordinate of the upper-left corner of the rectangle.
widthInt32The width of the rectangle, in pixels.
heightInt32The height of the rectangle, in pixels.

Instance memberFillText(text, x, y)

Draws filled text on the canvas. The default color of the text is black.

ParameterTypeDescription
textStringSpecifies the text that will be written on the canvas.
xInt32The x-coordinate where to start painting the text (relative to the canvas).
yInt32The y-coordinate where to start painting the text (relative to the canvas)

Instance memberFillText(text, location)

Draws filled text on the canvas. The default color of the text is black.

ParameterTypeDescription
textStringSpecifies the text that will be written on the canvas.
locationPointThe x-coordinate and y-coordinate where to start painting the text (relative to the canvas).

Instance memberGetLineDash()

Returns the current line dash pattern.

Returns: Int32[]. A list of numbers that specifies distances to alternately draw a line and a gap (in coordinate space units).

Instance memberLineTo(x, y)

Adds a new point and creates a line TO that point FROM the last specified point in the canvas (this method does not draw the line).

ParameterTypeDescription
xInt32The x-coordinate of where to create the line to.
yInt32The y-coordinate of where to create the line to.

Instance memberLineTo(location)

Adds a new point and creates a line TO that point FROM the last specified point in the canvas (this method does not draw the line).

ParameterTypeDescription
locationPointThe x-coordinate and y-coordinate of where to create the line to.

Instance memberMoveTo(x, y)

Moves the path to the specified point in the canvas, without creating a line.

ParameterTypeDescription
xInt32The x-coordinate of where to move the path to.
yInt32The y-coordinate of where to move the path to.

Use the stroke() method to actually draw the path on the canvas.

Instance memberMoveTo(location)

Moves the path to the specified point in the canvas, without creating a line.

ParameterTypeDescription
locationPointThe x-coordinate and y-coordinate of where to move the path to.

Use the stroke() method to actually draw the path on the canvas.

Instance memberQuadraticCurveTo(cpx, cpy, x, y)

Adds a point to the current path by using the specified control points that represent a quadratic Bézier curve.

ParameterTypeDescription
cpxInt32The x-coordinate of the Bézier control point.
cpyInt32The y-coordinate of the Bézier control point.
xInt32The x-coordinate of the ending point.
yInt32The y-coordinate of the ending point.

A quadratic Bézier curve requires two points. The first point is a control point that is used in the quadratic Bézier calculation and the second point is the ending point for the curve. The starting point for the curve is the last point in the current path. If a path does not exist, use the beginPath() and moveTo() methods to define a starting point.

Instance memberRect(rect)

Creates a rectangle.

ParameterTypeDescription
rectRectangleRectangle's coordinates and size.

Instance memberRect(x, y, width, height)

Creates a rectangle.

ParameterTypeDescription
xInt32The x-coordinate of the upper-left corner of the rectangle.
yInt32The y-coordinate of the upper-left corner of the rectangle.
widthInt32The width of the rectangle, in pixels.
heightInt32The height of the rectangle, in pixels.

Instance memberRestore()

Returns previously saved path state and attributes.

Instance memberRotate(degrees)

Method rotates the current drawing.

ParameterTypeDescription
degreesSingleThe rotation angle, in degrees.

The rotation will only affect drawings made AFTER the rotation is done.

Instance memberSave()

Saves the state of the current context.

Instance memberScale(scaleWidth, scaleHeight)

Scales the current drawing, bigger or smaller.

ParameterTypeDescription
scaleWidthSingleScales the width of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)
scaleHeightSingleScales the height of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)

Instance memberScale(scale)

Scales the current drawing, bigger or smaller.

ParameterTypeDescription
scaleSizeFScales the width of the current drawing (1=100%, 0.5=50%, 2=200%, etc.)

Instance memberSetLineDash(segments)

Sets the line dash pattern.

ParameterTypeDescription
segmentsInt32[]A list of numbers that specifies distances to alternately draw a line and a gap (in coordinate space units). If the number of elements in the array is odd, the elements of the array get copied and concatenated. For example, [5, 15, 25] will become [5, 15, 25, 5, 15, 25].

Instance memberSetTransform(scaleWidth, skewHoriz, skewVert, scaleHeight, x, y)

Resets the current transform to the identity matrix, and then runs transform() with the same arguments.

ParameterTypeDescription
scaleWidthSingleScales the drawing horizontally.
skewHorizSingleSkew the drawing horizontally.
skewVertSingleSkew the drawing vertically.
scaleHeightSingleScales the drawing vertically.
xInt32Moves the drawing horizontally
yInt32Moves the drawing vertically.

The transformation will only affect drawings made after the transform() method is called. The transform() method behaves relatively to other transformations made by rotate(), scale(), translate(), or transform(). Example: If you already have set your drawing to scale by two, and the transform() method scales your drawings by two, your drawings will now scale by four.

Instance memberStroke()

Draws the path you have defined.

Instance memberStrokeRect(rect)

Draws a rectangle (no fill). The default color of the stroke is black.

ParameterTypeDescription
rectRectangleRectangle's coordinates and size.

Instance memberStrokeRect(x, y, width, height)

Draws a rectangle (no fill). The default color of the stroke is black.

ParameterTypeDescription
xInt32The x-coordinate of the upper-left corner of the rectangle.
yInt32The y-coordinate of the upper-left corner of the rectangle.
widthInt32The width of the rectangle, in pixels.
heightInt32The height of the rectangle, in pixels.

Instance memberStrokeText(text, x, y)

Draws text (with no fill) on the canvas. The default color of the text is black.

ParameterTypeDescription
textStringSpecifies the text that will be written on the canvas.
xInt32The x-coordinate where to start painting the text (relative to the canvas).
yInt32The y-coordinate where to start painting the text (relative to the canvas)

Instance memberStrokeText(text, location)

Draws text (with no fill) on the canvas. The default color of the text is black.

ParameterTypeDescription
textStringSpecifies the text that will be written on the canvas.
locationPointThe x-coordinate and y-coordinate where to start painting the text (relative to the canvas).

Instance memberTransform(scaleWidth, skewHoriz, skewVert, scaleHeight, x, y)

Replaces the current transformation matrix.

ParameterTypeDescription
scaleWidthSingleScales the drawing horizontally.
skewHorizSingleSkew the drawing horizontally.
skewVertSingleSkew the drawing vertically.
scaleHeightSingleScales the drawing vertically.
xInt32Moves the drawing horizontally
yInt32Moves the drawing vertically.

The transformation will only affect drawings made after the transform() method is called. The transform() method behaves relatively to other transformations made by rotate(), scale(), translate(), or transform(). Example: If you already have set your drawing to scale by two, and the transform() method scales your drawings by two, your drawings will now scale by four.

Instance memberTranslate(x, y)

Remaps the (0,0) position on the canvas.

ParameterTypeDescription
xInt32The value to add to horizontal (x) coordinates.
yInt32The value to add to vertical (y) coordinates.

When you call a method such as fillRect() after translate(), the value is added to the x- and y-coordinate values.

Instance memberTranslate(location)

Remaps the (0,0) position on the canvas.

ParameterTypeDescription
locationPointThe value to add to horizontal (x) and vertical (y) coordinates.

When you call a method such as fillRect() after translate(), the value is added to the x- and y-coordinate values.

Events

Instance memberRedraw

EventHandler Fired when the canvas requires a full redraw.

Implements

NameDescription
IBindableComponentBindable components implement this interface.
IDropTargetControls that support drag & drop operations implement this interface.
IWisejComponentAll wisej components implement this interface.
IWisejControlAll wisej controls derived from the Control class must implement this interface.
IWisejHandlerRepresents a Wisej component that is capable of handling postback requests from the client.
IWisejSerializableAllows an object to serialize itself.