HTML 5 Canvas Reference Manual
- HTML Video/Audio
- HTML Document Type
Describe
HTML5 <canvas> tags are used to draw images (through scripting, usually JavaScript).
However, the,<canvas> element itself does not have the ability to draw (it is just a container for graphics)-You must use a script to accomplish the actual drawing task.
The GetContext () method returns an object that provides methods and properties for drawing on the canvas.
This manual provides complete getcontext ("2d") object properties and methods that you can use to draw text, lines, rectangles, circles, and so on on the canvas.
Browser support
Internet Explorer 9, Firefox, Opera, Chrome, and Safari support <canvas> and its properties and methods.
Note: Internet Explorer 8 and earlier versions do not support the <canvas> element.
colors, styles, and shadows
Properties |
Description |
FillStyle |
Sets or returns the color, gradient, or pattern used to fill the drawing |
Strokestyle |
Sets or returns the color, gradient, or pattern used for a stroke |
Shadowcolor |
Sets or returns the color used for shadows |
Shadowblur |
Sets or returns the level of blur used for shadows |
Shadowoffsetx |
Sets or returns the horizontal distance of the shadow distance shape |
Shadowoffsety |
Sets or returns the vertical distance of the shadow distance shape |
Method |
Description |
Createlineargradient () |
Create a linear gradient (used on canvas content) |
Createpattern () |
Repeats the specified element in the specified direction |
Createradialgradient () |
Create Radial/annular gradients (used on canvas content) |
Addcolorstop () |
Specify the color and stop position in the gradient object |
Line Style
Properties |
Description |
LineCap |
Sets or returns the end endpoint style for a line |
LineJoin |
Sets or returns the type of corner created when two lines intersect |
LineWidth |
Sets or returns the current line width |
Miterlimit |
Sets or returns the maximum miter length |
Rectangular
Method |
Description |
Rect () |
Create a rectangle |
FillRect () |
Draw a "filled" rectangle |
Strokerect () |
Draw Rectangle (No fill) |
Clearrect () |
Clears the specified pixel within the given rectangle |
Path
Method |
Description |
Fill () |
Fills the current drawing (path) |
Stroke () |
Draw a defined path |
Beginpath () |
Start a path, or reset the current path |
MoveTo () |
Move a path to a specified point in the canvas without creating a line |
Closepath () |
Creates a path from the current point back to the starting point |
LineTo () |
Add a new point, and then create a line from that point to the last specified point in the canvas |
Clip () |
Cut an area of any shape and size from the original canvas |
Quadraticcurveto () |
Create a Bezier curve of two times |
Beziercurveto () |
Creating three-cubic Bezier curves |
Arc () |
Create Arcs/curves (for creating circular or partial circles) |
ArcTo () |
Create an arc/curve between two tangents |
Ispointinpath () |
Returns true if the specified point is in the current path, otherwise false |
Transformation
Method |
Description |
Scale () |
Scale the current drawing to a larger or smaller |
Rotate () |
Rotate the current drawing |
Translate () |
Remap (0,0) locations on the canvas |
Transform () |
Replace the current transformation matrix of the drawing |
SetTransform () |
Resets the current transformation to the unit matrix. Then run transform () |
Text
Properties |
Description |
Font |
Sets or returns the current font property of the text content |
TextAlign |
Sets or returns the current alignment of text content |
Textbaseline |
Sets or returns the current text baseline to use when drawing text |
Method |
Description |
Filltext () |
Draw "filled" text on canvas |
Stroketext () |
Draw text on the canvas (no fill) |
Measuretext () |
Returns the object that contains the specified text width |
Image rendering
Method |
Description |
DrawImage () |
Draw an image, canvas, or video to the canvas |
Pixel operation
Properties |
Description |
Width |
Returns the width of the ImageData object |
Height |
Returns the height of the ImageData object |
Data |
Returns an object that contains the image data for the specified ImageData object |
Method |
Description |
Createimagedata () |
To create a new, blank ImageData object |
Getimagedata () |
Returns a ImageData object that copies pixel data for a specified rectangle on the canvas |
Putimagedata () |
Put the image data (from the specified ImageData object) back onto the canvas |
Synthesis
Properties |
Description |
Globalalpha |
Sets or returns the current alpha or transparent value of a drawing |
Globalcompositeoperation |
Sets or returns how the new image is drawn to an existing image |
Other
Method |
Description |
Save () |
Save the state of the current environment |
Restore () |
Returns the previously saved path state and properties |
CreateEvent () |
|
GetContext () |
|
Todataurl () |
|
HTML 5 Canvas Reference Manual