Interface: ICanvas

ICanvas

Common interface for HTMLCanvasElement, OffscreenCanvas, and other custom canvas classes.

Properties:
Name Type Description
height number

Height of the canvas.

parentNode ICanvasParentNode | null

Parent node of the canvas.

style ICanvasStyle

Style of the canvas.

width number

Width of the canvas.

Extends

  • PixiMixins.ICanvas
  • Partial.<EventTarget>

Members

height number

Height of the canvas.

parentNode ICanvasParentNode | null readonly

Parent node of the canvas.

style ICanvasStyle readonly

Style of the canvas.

width number

Width of the canvas.

Methods

addEventListener (type, listener, options) void

Adds the listener for the specified event.

Name Type Description
type string

The type of event to listen for.

listener EventListenerOrEventListenerObject

The callback to invoke when the event is fired.

options boolean | AddEventListenerOptions

The options for adding event listener.

convertToBlob (options) Promise<Blob>

Get the content of the canvas as Blob.

Name Type Attributes Description
options object <optional>

The options for creating Blob.

options.type string <optional>

A string indicating the image format. The default type is image/png; that type is also used if the given type isn't supported.

options.quality string <optional>

A number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

Returns:
Type Description
Promise<Blob> A Promise returning a Blob object representing the image contained in the canvas.

dispatchEvent (event) boolean

Dispatches a event.

Name Type Description
event Event

The Event object to dispatch. Its Event.target property will be set to the current EventTarget.

Returns:
Type Description
boolean Returns false if event is cancelable, and at least one of the event handlers which received event called Event.preventDefault(). Otherwise true.

getBoundingClientRect () ICanvasRect

Get the position and the size of the canvas.

Returns:
Type Description
ICanvasRect The smallest rectangle which contains the entire canvas.

getContext (contextId, options) RenderingContext | unknown

Get rendering context of the canvas.

Name Type Attributes Description
contextId ContextIds

The identifier of the type of context to create.

options ContextSettings <optional>

The options for creating context.

Returns:
Type Description
RenderingContext | unknown The created context, or null if contextId is not supported.

removeEventListener (type, listener, options) void

Removes the listener for the specified event.

Name Type Description
type string

The type of event to listen for.

listener EventListenerOrEventListenerObject

The callback to invoke when the event is fired.

options boolean | EventListenerOptions

The options for removing event listener.

toBlob (callback, type, quality) void

Creates a Blob from the content of the canvas.

Name Type Attributes Description
callback unknown

A callback function with the resulting Blob object as a single argument. null may be passed if the image cannot be created for any reason.

type string <optional>

A string indicating the image format. The default type is image/png; that type is also used if the given type isn't supported.

quality string <optional>

A number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

toDataURL (type, quality) string

Get the content of the canvas as data URL.

Name Type Attributes Description
type string <optional>

A string indicating the image format. The default type is image/png; that type is also used if the given type isn't supported.

quality string <optional>

A number between 0 and 1 indicating the image quality to be used when creating images using file formats that support lossy compression (such as image/jpeg or image/webp). A user agent will use its default quality value if this option is not specified, or if the number is outside the allowed range.

Returns:
Type Description
string A string containing the requested data URL.