Dart API Referencedart:htmlCanvasElement

CanvasElement Interface

DOM canvas elements expose the HTMLCanvasElement interface, which provides properties and methods for manipulating the layout and presentation of canvas elements. The HTMLCanvasElement interface inherits the properties and methods of the element object interface.

Extends

Element

Constructors

Code new CanvasElement([int width, int height]) #

CanvasElement([int width, int height]);

Methods

Code Object getContext(String contextId) #

Returns a drawing context on the canvas, or null if the context ID is not supported. A drawing context lets you draw on the canvas. The currently accepted values are "2d" and "experimental-webgl". The "experimental-webgl" context is only available on browsers that implement WebGL. Calling getContext with "2d" returns a CanvasRenderingContext2D Object, whereas calling it with "experimental-webgl" returns a WebGLRenderingContext Object.
Object getContext(String contextId);

Code String toDataURL(String type) #

Returns a data: URL containing a representation of the image in the format specified by type (defaults to PNG).

  • If the height or width of the canvas is 0, "data:," representing the empty string, is returned.
  • If the type requested is not image/png, and the returned value starts with data:image/png, then the requested type is not supported.
  • Chrome supports the image/webp type.
  • If the requested type is image/jpeg or image/webp, then the second argument, if it is between 0.0 and 1.0, is treated as indicating image quality; if the second argument is anything else, the default value for image quality is used. Other arguments are ignored.
String toDataURL(String type);

Fields

Code final CanvasRenderingContext2D context2d #

final CanvasRenderingContext2D context2d;

Code int height #

Reflects the height HTML attribute, specifying the height of the coordinate space in CSS pixels.
int height;

Code int width #

Reflects the width HTML attribute, specifying the width of the coordinate space in CSS pixels.
int width;

This page includes content from the Mozilla Foundation that is graciously licensed under a Creative Commons: Attribution-Sharealike license. Mozilla has no other association with Dart or dartlang.org. We encourage you to improve the web by contributing to The Mozilla Developer Network.