<br />

The wrapper class for MediaPipe Image objects. Images are stored as `ImageData`, `ImageBitmap` or `WebGLTexture` objects. You can convert the underlying type to any other type by passing the desired type to `getAs...()`. As type conversions can be expensive, it is recommended to limit these conversions. You can verify what underlying types are already available by invoking `has...()`. Images that are returned from a MediaPipe Tasks are owned by by the underlying C++ Task. If you need to extend the lifetime of these objects, you can invoke the `clone()` method. To free up the resources obtained during any clone or type conversion operation, it is important to invoke `close()` on the `MPImage` instance. Converting to and from ImageBitmap requires that the MediaPipe task is initialized with an `OffscreenCanvas`. As we require WebGL2 support, this places some limitations on Browser support as outlined here: https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext

**Signature:**

```typescript
export declare class MPImage 
```

## Properties

| Property | Modifiers | Type | Description |
|---|---|---|---|
| [canvas](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimagecanvas) |   | HTMLCanvasElement \| OffscreenCanvas \| undefined | Returns the canvas element that the image is bound to. |
| [width](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimagewidth) |   | number | Returns the width of the image. |
| [height](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimageheight) |   | number | Returns the height of the image. |

## Methods

| Method | Modifiers | Description |
|---|---|---|
| [hasImageData()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimagehasimagedata) |   | Returns whether this `MPImage` contains a mask of type `ImageData`. |
| [hasImageBitmap()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimagehasimagebitmap) |   | Returns whether this `MPImage` contains a mask of type `ImageBitmap`. |
| [hasWebGLTexture()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimagehaswebgltexture) |   | Returns whether this `MPImage` contains a mask of type `WebGLTexture`. |
| [getAsImageData()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimagegetasimagedata) |   | Returns the underlying image as an `ImageData` object. Note that this involves an expensive GPU to CPU transfer if the current image is only available as an `ImageBitmap` or `WebGLTexture`. |
| [getAsImageBitmap()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimagegetasimagebitmap) |   | Returns the underlying image as an `ImageBitmap`. Note that conversions to `ImageBitmap` are expensive, especially if the data currently resides on CPU. Processing with `ImageBitmap`s requires that the MediaPipe Task was initialized with an `OffscreenCanvas` with WebGL2 support. See https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext for a list of supported platforms. |
| [getAsWebGLTexture()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimagegetaswebgltexture) |   | Returns the underlying image as a `WebGLTexture` object. Note that this involves a CPU to GPU transfer if the current image is only available as an `ImageData` object. The returned texture is bound to the current canvas (see `.canvas`). |
| [clone()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimageclone) |   | Creates a copy of the resources stored in this `MPImage`. You can invoke this method to extend the lifetime of an image returned by a MediaPipe Task. Note that performance critical applications should aim to only use the `MPImage` within the MediaPipe Task callback so that copies can be avoided. |
| [close()](https://developers.google.com/edge/api/mediapipe/js/tasks-vision.mpimage.md.txt#mpimageclose) |   | Frees up any resources owned by this `MPImage` instance. Note that this method does not free images that are owned by the C++ Task, as these are freed automatically once you leave the MediaPipe callback. Additionally, some shared state is freed only once you invoke the Task's `close()` method. |

## MPImage.canvas

Returns the canvas element that the image is bound to.

**Signature:**

```typescript
readonly canvas: HTMLCanvasElement | OffscreenCanvas | undefined;
```

## MPImage.width

Returns the width of the image.

**Signature:**

```typescript
readonly width: number;
```

## MPImage.height

Returns the height of the image.

**Signature:**

```typescript
readonly height: number;
```

## MPImage.hasImageData()

Returns whether this `MPImage` contains a mask of type `ImageData`.

**Signature:**

```typescript
hasImageData(): boolean;
```

**Returns:**

boolean

## MPImage.hasImageBitmap()

Returns whether this `MPImage` contains a mask of type `ImageBitmap`.

**Signature:**

```typescript
hasImageBitmap(): boolean;
```

**Returns:**

boolean

## MPImage.hasWebGLTexture()

Returns whether this `MPImage` contains a mask of type `WebGLTexture`.

**Signature:**

```typescript
hasWebGLTexture(): boolean;
```

**Returns:**

boolean

## MPImage.getAsImageData()

Returns the underlying image as an `ImageData` object. Note that this involves an expensive GPU to CPU transfer if the current image is only available as an `ImageBitmap` or `WebGLTexture`.

**Signature:**

```typescript
getAsImageData(): ImageData;
```

**Returns:**

ImageData

## MPImage.getAsImageBitmap()

Returns the underlying image as an `ImageBitmap`. Note that conversions to `ImageBitmap` are expensive, especially if the data currently resides on CPU. Processing with `ImageBitmap`s requires that the MediaPipe Task was initialized with an `OffscreenCanvas` with WebGL2 support. See https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCanvas/getContext for a list of supported platforms.

**Signature:**

```typescript
getAsImageBitmap(): ImageBitmap;
```

**Returns:**

ImageBitmap

## MPImage.getAsWebGLTexture()

Returns the underlying image as a `WebGLTexture` object. Note that this involves a CPU to GPU transfer if the current image is only available as an `ImageData` object. The returned texture is bound to the current canvas (see `.canvas`).

**Signature:**

```typescript
getAsWebGLTexture(): WebGLTexture;
```

**Returns:**

WebGLTexture

## MPImage.clone()

Creates a copy of the resources stored in this `MPImage`. You can invoke this method to extend the lifetime of an image returned by a MediaPipe Task. Note that performance critical applications should aim to only use the `MPImage` within the MediaPipe Task callback so that copies can be avoided.

**Signature:**

```typescript
clone(): MPImage;
```

**Returns:**

MPImage

## MPImage.close()

Frees up any resources owned by this `MPImage` instance. Note that this method does not free images that are owned by the C++ Task, as these are freed automatically once you leave the MediaPipe callback. Additionally, some shared state is freed only once you invoke the Task's `close()` method.

**Signature:**

```typescript
close(): void;
```

**Returns:**

void