Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BaseImage

Base class for all images.

Hierarchy

Index

Constructors

Protected constructor

  • new BaseImage(width: number, height: number): BaseImage
  • Creates a new image with the given size.

    Parameters

    • width: number

      The image width in pixels.

    • height: number

      The image height in pixels.

    Returns BaseImage

Properties

Protected height

height: number

The image height in pixels.

Protected width

width: number

The image width in pixels.

Methods

draw

  • draw(ctx: CanvasRenderingContext2D, x?: number, y?: number): void
  • Draws the image onto the given rendering context.

    Parameters

    • ctx: CanvasRenderingContext2D

      The rendering context to draw the image to.

    • Default value x: number = 0

      Optional horizontal target position. Defaults to 0.

    • Default value y: number = 0

      Optional vertical target position. Defaults to 0.

    Returns void

getColor

  • getColor(x: number, y: number): number
  • Returns the RGBA color at the specified position.

    Parameters

    • x: number

      The horizontal pixel position.

    • y: number

      The vertical pixel position.

    Returns number

    The RGBA color at the specified position.

getHeight

  • getHeight(): number
  • Returns the image height in pixels.

    Returns number

    The image height in pixels.

getWidth

  • getWidth(): number
  • Returns the image width in pixels.

    Returns number

    The image width in pixels.

toCanvas

  • toCanvas(): HTMLCanvasElement
  • Creates and returns a new canvas containing the image.

    Returns HTMLCanvasElement

    The created canvas.

toDataUrl

  • toDataUrl(type?: undefined | string, ...args: any[]): string
  • Creates and returns an image data URL.

    Parameters

    • Optional type: undefined | string

      Optional image mime type. Defaults to image/png.

    • Rest ...args: any[]

      Optional additional encoder parameters. For image/jpeg this is the image quality between 0 and 1 with a default value of 0.92.

    Returns string

    The created data URL.

toImage

  • toImage(type?: undefined | string, ...args: any[]): HTMLImageElement
  • Creates and returns a HTML image.

    Parameters

    • Optional type: undefined | string

      Optional image mime type. Defaults to image/png.

    • Rest ...args: any[]

      Optional additional encoder parameters. For image/jpeg this is the image quality between 0 and 1 with a default value of 0.92.

    Returns HTMLImageElement

    The created HTML image.

Generated using TypeDoc