Interface ICanvas

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

Memberof

PIXI

interface ICanvas {
    addEventListener?: {
        (type, listener, options?): void;
        <K>(type, listener, options?): void;
    };
    height: number;
    parentNode?: null | ICanvasParentNode;
    removeEventListener?: {
        (type, listener, options?): void;
        <K>(type, listener, options?): void;
    };
    style?: ICanvasStyle;
    width: number;
    convertToBlob?(options?): Promise<Blob>;
    dispatchEvent(event): boolean;
    getBoundingClientRect?(): ICanvasRect;
    getContext(contextId, options?): null | ICanvasRenderingContext2D;
    getContext(contextId, options?): null | ImageBitmapRenderingContext;
    getContext(contextId, options?): null | WebGLRenderingContext;
    getContext(contextId, options?): null | WebGL2RenderingContext;
    getContext(contextId, options?): null | RenderingContext;
    toBlob?(callback, type?, quality?): void;
    toDataURL?(type?, quality?): string;
}

Hierarchy

  • ICanvas
  • Partial<EventTarget>
    • ICanvas

Properties

addEventListener?: {
    (type, listener, options?): void;
    <K>(type, listener, options?): void;
}

Adds the listener for the specified event.

Type declaration

    • (type, listener, options?): void
    • Parameters

      • type: string

        The type of event to listen for.

      • listener: EventListenerOrEventListenerObject

        The callback to invoke when the event is fired.

      • Optional options: boolean | AddEventListenerOptions

        The options for adding event listener.

      Returns void

    • <K>(type, listener, options?): void
    • Type Parameters

      Parameters

      • type: K

        The type of event to listen for.

      • listener: ((this, ev) => any)

        The callback to invoke when the event is fired.

      • Optional options: boolean | AddEventListenerOptions

        The options for adding event listener.

      Returns void

Method

Returns

height: number

Height of the canvas.

parentNode?: null | ICanvasParentNode

Parent node of the canvas.

removeEventListener?: {
    (type, listener, options?): void;
    <K>(type, listener, options?): void;
}

Removes the listener for the specified event.

Type declaration

    • (type, listener, options?): void
    • Parameters

      • type: string

        The type of event to listen for.

      • listener: EventListenerOrEventListenerObject

        The callback to invoke when the event is fired.

      • Optional options: boolean | EventListenerOptions

        The options for removing event listener.

      Returns void

    • <K>(type, listener, options?): void
    • Type Parameters

      Parameters

      • type: K

        The type of event to listen for.

      • listener: ((this, ev) => any)

        The callback to invoke when the event is fired.

      • Optional options: boolean | EventListenerOptions

        The options for removing event listener.

      Returns void

Method

Returns

style?: ICanvasStyle

Style of the canvas.

width: number

Width of the canvas.

Methods

  • Get the content of the canvas as Blob.

    Parameters

    • Optional options: {
          quality?: number;
          type?: string;
      }

      The options for creating Blob.

      • Optional quality?: number

        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.

      • Optional type?: string

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

    Returns Promise<Blob>

    A Promise returning a Blob object representing the image contained in the canvas.

  • Dispatches a event.

    Parameters

    • event: Event

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

    Returns boolean

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

  • Get the position and the size of the canvas.

    Returns ICanvasRect

    The smallest rectangle which contains the entire canvas.

  • Get rendering context of the canvas.

    Parameters

    Returns null | ICanvasRenderingContext2D

    The created context, or null if contextId is not supported.

  • Parameters

    • contextId: "bitmaprenderer"
    • Optional options: ImageBitmapRenderingContextSettings

    Returns null | ImageBitmapRenderingContext

  • Parameters

    • contextId: "webgl" | "experimental-webgl"
    • Optional options: WebGLContextAttributes

    Returns null | WebGLRenderingContext

  • Parameters

    • contextId: "webgl2" | "experimental-webgl2"
    • Optional options: WebGLContextAttributes

    Returns null | WebGL2RenderingContext

  • Parameters

    Returns null | RenderingContext

  • Creates a Blob from the content of the canvas.

    Parameters

    • callback: ((blob) => void)

      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.

        • (blob): void
        • Parameters

          • blob: null | Blob

          Returns void

    • Optional type: string

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

    • Optional quality: number

      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 void

  • Get the content of the canvas as data URL.

    Parameters

    • Optional type: string

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

    • Optional quality: number

      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 string

    A string containing the requested data URL.

Generated using TypeDoc