共用方式為


ICanvasRenderingContext2D interface

Provides an object that represents a two-dimensional surface that has an origin (0,0) at the upper-left corner, with x-coordinates increasing as you move right and y-coordinates increasing as you move down.

Members

The ICanvasRenderingContext2D interface inherits from the IDispatch interface. ICanvasRenderingContext2D also has these types of members:

  • Methods
  • Properties

Methods

The ICanvasRenderingContext2D interface has these methods.

Method Description
arc

Adds points to a path that represents an arc.

arcTo

Draws an arc of a fixed radius between two tangents that are defined by the current point in a path and two additional points.

beginPath

Resets the current path.

bezierCurveTo

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

clearRect

Clears the pixels on a CanvasRenderingContext2D object within a given rectangle.

clip

Specifies a new clipping region.

closePath

Closes the current subpath and starts a new subpath that has a start point that is equal to the end of the closed subpath.

createImageData

Returns a CanvasImageData object with the given dimensions in CSS pixels.

createLinearGradient

Creates an object that represents a linear gradient to use in a canvas context.

createPattern

Returns a CanvasPattern object that repeats the specified element in the specified direction.

createRadialGradient

Returns an object that represents a radial or circular gradient to use in a canvas context.

drawImage

Draws a specified image onto a canvas.

fill

Fills subpaths by using the current fill style.

fillRect

Paints a rectangle onto a CanvasRenderingContext2D object by using the current ICanvasRenderingContext2D::fillStyle.

fillText

Renders filled text to the canvas by using the current ICanvasRenderingContext2D::fillStyle and font.

getImageData

Returns an ICanvasImageData object that represents the pixel data for the specified rectangle on a canvas. Use the data property to get a CanvasPixelArray to manipulate individual pixel data.

isPointInPath

Determines if the specified point is in the current path.

lineTo

Adds a new point to a subpath and connects that point to the last point in the subpath by using a straight line.

measureText

Returns a CanvasTextMetrics object that contains the width of the specified text.

moveTo

Creates a new subpath by using the specified point.

putImageData

Paints the data from a specified CanvasImageData object onto a canvas.

quadraticCurveTo

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

rect

Creates a new closed rectangular subpath.

restore

Returns previously saved CanvasRenderingContext2D path state and attributes.

rotate

Rotates the current context coordinates (that is, a transformation matrix).

save

Saves the state of the current context.

scale

Scales the current context by the specified horizontal (x) and vertical (y) factors.

setTransform

Resets the current transformation matrix of the context back to the identity matrix and then multiplies it by the specified matrix.

stroke

Renders the strokes of the current subpath by using the current stroke styles.

strokeRect

Creates an outline of the specified rectangle on a canvas by using the current stroke, line width, and join styles.

strokeText

Renders the specified text at the specified position by using the current ICanvasRenderingContext2D::font, ICanvasRenderingContext2D::lineWidth, and ICanvasRenderingContext2D::strokeStyle property.

transform

Modifies the transformation matrix of the current context.

translate

Specifies values to move the origin point in a canvas.

 

Properties

The ICanvasRenderingContext2D interface has these properties.

Property Access type Description

canvas

Gets a back reference to the canvas object that the current context derives from.

fillStyle

Gets or sets the current style that is used to fill shapes.

font

Read/write

Gets or sets the current font for the context.

globalAlpha

Gets or sets the current alpha or transparency value that is applied to global composite rendering operations.

globalCompositeOperation

Gets or sets a value that indicates how source images are drawn onto a destination image.

lineCap

Gets or sets the current line cap style.

lineJoin

Gets or sets the type of corner that is created when two lines meet.

lineWidth

Gets or sets the current line width, in pixels.

miterLimit

Gets or sets the maximum allowed ratio between half of the ICanvasRenderingContext2D::lineWidth value and the miter length.

shadowBlur

Read/write

Gets or sets the current level of blur that is applied to shadows.

shadowColor

Read/write

Gets or sets the color to use for shadows.

shadowOffsetX

Read/write

Gets or sets the horizontal distance of a shadow from a shape.

shadowOffsetY

Read/write

Gets or sets the vertical distance of a shadow from a shape.

strokeStyle

Read/write

Gets or sets the current style that is used for strokes (lines) on shapes.

textAlign

Gets or sets the current anchor point or alignment settings for text in the current context.

textBaseline

Gets or sets the current settings for the font baseline alignment.

 

Remarks

The ICanvasRenderingContext2D interface provides most of the drawing methods and properties that are used with the IHTMLCanvasElement object.

You can include only one ICanvasRenderingContext2D object per canvas. Additional calls to this interface return the same context.

To see an interactive demo, see the Windows Internet Explorer 9 Test Drive Canvas demo.

Requirements

Minimum supported client

Windows Vista with SP1, Windows 7

Minimum supported server

Windows Server 2008 R2

Header

Mshtml.h

IDL

Mshtml.idl

DLL

Mshtml.dll

See also

IDispatch