Class ImageRef

Represent an image that is backed by native resources and can be created from various sources.

Example

Since the instance of the class is backed by native resources and implements AsyncDisposable it's highly recommended to use the await using syntax when an instance is created or is received from an API:

await using instance = await ImageRef.fromPath('path/to/image.jpg');

Alternatively, one can explicitly call release method to release the native resources or use autorelease convenience function. If neither is used, the resource will be released when the instance is garbage collected which is not recommended.

Hierarchy (view full)

Implements

  • AsyncDisposable

Properties

uniqueId: null | string

Returns the unique identifier of the image native resource. Must not be modified.

Methods

  • Returns Promise<void>

  • Encodes the image with given options.

    Parameters

    Returns Promise<Uint8Array>

    Encoded image data as a Uint8Array.

  • Returns the image information.

    Returns Promise<ImageInfo>

    image information

  • Releases the native resources associated with this image.

    Returns Promise<void>

  • Marks this object as retained, meaning that it will not be automatically released when exit from autorelease function occurs.

    Returns void

  • Saves the image to the given path with given options.

    Parameters

    • path: string

      Path to save the image to.

    • options: SaveImageOptions = ...

      Options used during image saving.

    Returns Promise<void>

  • Creates an image from the given encoded buffer e.g. from jpeg with given options.

    Parameters

    • buffer: Uint8Array

      Encoded image data as a Uint8Array.

    • options: BufferImageLoadOptions = ...

      Options used during image loading.

    Returns Promise<ImageRef>

    Loaded image reference.

  • Creates an image from the given path with given options.

    Parameters

    • path: string

      Path to the image file.

    • options: PathImageLoadOptions = ...

      Options used during image loading

    Returns Promise<ImageRef>

    Loaded image reference.

  • Releases all alive images despite any existing references.

    Returns Promise<void>