HTML5 Interface Element Canvas Reference Manual

Source: Internet
Author: User

HTML5 Interface Element Canvas Reference Manual

HTML5 Interface Element Canvas Reference Manual

Beautiful Life of the sun and fire god (http://blog.csdn.net/opengl_es)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Sun huoshen's beautiful life-this blog focuses on Agile development and mobile and IOT device research: iOS, Android, Html5, Arduino, pcDuino, otherwise, this blog post is rejected or reprinted. Thank you for your cooperation.



HTML5 Interface Element Canvas Reference Manual
HTML Canvas Reference



Description
Description


The HTML5 Tag is used to draw graphics, on the fly, via scripting (usually JavaScript ).

However, Element has no drawing abilities of its own (it is only a container for graphics)-you must use a script to actually draw the graphics.

The getContext () method returns an object that provides methods and properties for drawing on the canvas.

This reference will cover the properties and methods of the getContext ("2d") object, which can be used to draw text, lines, boxes, circles, and more-on the canvas.



Browser support
Browser Support


Internet Explorer 9, Firefox, Opera, Chrome, and Safari support And its properties and methods.

Note:Internet Explorer 8 and earlier versions, do not support Element.



Colors, styles, and shadows
Colors, Styles, and Shadows


Property

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 strokes

ShadowColor

Sets or returns the color to use for shadows

ShadowBlur

Sets or returns the blur level for shadows

ShadowOffsetX

Sets or returns the horizontal distance of the shadow from the shape

ShadowOffsetY

Sets or returns the vertical distance of the shadow from the shape


Method

Description

CreateLinearGradient ()

Creates a linear gradient (to use on canvas content)

CreatePattern ()

Repeats a specified element in the specified direction

CreateRadialGradient ()

Creates a radial/circular gradient (to use on canvas content)

AddColorStop ()

Specifies the colors and stop positions in a gradient object




Line Style
Line Styles


Property

Description

LineCap

Sets or returns the style of the end caps for a line

LineJoin

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

LineWidth

Sets or returns the current line width

MiterLimit

Sets or returns the maximum miter length



Rectangle
Rectangles


Method

Description

Rect ()

Creates a rectangle

FillRect ()

Draws a "filled" rectangle

StrokeRect ()

Draws a rectangle (no fill)

ClearRect ()

Clears the specified pixels within a given rectangle


Path
Paths

Method

Description

Fill ()

Fills the current drawing (path)

Stroke ()

Actually draws the path you have defined

BeginPath ()

Begins a path, or resets the current path

MoveTo ()

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

ClosePath ()

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

LineTo ()

Adds a new point and creates a line from that point to the last specified point in the canvas

Clip ()

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

QuadraticCurveTo ()

Creates a quadratic bégiscurve

BezierCurveTo ()

Creates a cubic bégiscurve

Arc ()

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

ArcTo ()

Creates an arc/curve between two tangents

IsPointInPath ()

Returns true if the specified point is in the current path, otherwise false




Conversion
Transformations


Method

Description

Scale ()

Scales the current drawing bigger or smaller

Rotate ()

Rotates the current drawing

Translate ()

Remaps the (0, 0) position on the canvas

Transform ()

Replaces the current transformation matrix for the drawing

SetTransform ()

Resets the current transform to the identity matrix. Then runs transform ()




Text
Text


Property

Description

Font

Sets or returns the current font properties for text content

TextAlign

Sets or returns the current alignment for text content

TextBaseline

Sets or returns the current text baseline used when drawing text


Method

Description

FillText ()

Draws "filled" text on the canvas

StrokeText ()

Draws text on the canvas (no fill)

MeasureText ()

Returns an object that contains the width of the specified text




Image Rendering
Image Drawing


Method

Description

DrawImage ()

Draws an image, canvas, or video onto the canvas




Pixel operations
Pixel Manipulation

Property

Description

Width

Returns the width of an ImageData object

Height

Returns the height of an ImageData object

Data

Returns an object that contains image data of a specified ImageData object


Method

Description

CreateImageData ()

Creates a new, blank ImageData object

GetImageData ()

Returns an ImageData object that copies the pixel data for the specified rectangle on a canvas

PutImageData ()

Puts the image data (from a specified ImageData object) back onto the canvas




Hybrid
Compositing


Property

Description

GlobalAlpha

Sets or returns the current alpha or transparency value of the drawing

GlobalCompositeOperation

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




Others
Other


Method

Description

Save ()

Saves the state of the current context

Restore ()

Returns previously saved path state and attributes

CreateEvent ()

GetContext ()

ToDataURL ()







Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.