Class CanvasRenderTarget

CanvasRenderTarget is 2D render target which exposes a Canvas interface.

Hierarchy (view full)

Constructors

  • Parameters

    • width: number

      the desired width of the canvas

    • height: number

      the desired height of the canvas

    • attributes: {
          antiAlias: undefined | boolean;
          context: undefined | string;
          offscreenCanvas: undefined | boolean;
          preferWebGL1: undefined | boolean;
          transparent: undefined | boolean;
          willReadFrequently: undefined | boolean;
      } = defaultAttributes

      The attributes to create both the canvas and context

      • antiAlias: undefined | boolean

        Whether to enable anti-aliasing, use false (default) for a pixelated effect.

      • context: undefined | string

        the context type to be created ("2d", "webgl")

      • offscreenCanvas: undefined | boolean

        will create an offscreenCanvas if true instead of a standard canvas

      • preferWebGL1: undefined | boolean

        set to true for force using WebGL1 instead of WebGL2 (if supported)

      • transparent: undefined | boolean

        specify if the canvas contains an alpha channel

      • willReadFrequently: undefined | boolean

        Indicates whether or not a lot of read-back operations are planned

    Returns CanvasRenderTarget

Properties

WebGLVersion: any

the rendering context of this CanvasRenderTarget

canvas: any
context: any
glTextureUnit: any

Accessors

Methods

  • Returns an ImageData object representing the underlying pixel data for a specified portion of this canvas texture. (Note: when using getImageData(), it is highly recommended to use the willReadFrequently attribute when creatimg the corresponding canvas texture)

    Parameters

    • x: number

      The x-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted

    • y: number

      The y-axis coordinate of the top-left corner of the rectangle from which the ImageData will be extracted

    • width: number

      The width of the rectangle from which the ImageData will be extracted. Positive values are to the right, and negative to the left

    • height: number

      The height of the rectangle from which the ImageData will be extracted. Positive values are down, and negative are up

    Returns ImageData

    The ImageData extracted from this CanvasRenderTarget.

  • creates a Blob object representing the image contained in this canvas texture

    Parameters

    • Optionaltype: string = "image/png"

      A string indicating the image format

    • Optionalquality: 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 Promise<any>

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

    renderTarget.convertToBlob().then((blob) => console.log(blob));
    
  • returns a data URL containing a representation of the most recently rendered image of this canvas texture (not supported by OffscreenCanvas)

    Parameters

    • Optionaltype: string = "image/png"

      A string indicating the image format

    • Optionalquality: 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 Promise<any>

    A Promise returning a string containing the requested data URL.

    renderer.toDataURL().then((dataURL) => console.log(dataURL));
    
  • creates an ImageBitmap object from the most recently rendered image of this canvas texture

    Parameters

    • Optionaltype: string = "image/png"

      A string indicating the image format

    • Optionalquality: 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 Promise<any>

    A Promise returning an ImageBitmap.

    renderTarget.transferToImageBitmap().then((bitmap) => console.log(bitmap));