# CanvasOverlay

Artifact: [androidx.media3:media3-effect](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/effect/CanvasOverlay.java+class:androidx.media3.effect.CanvasOverlay)

*** ** * ** ***


```
@UnstableApi
public abstract class CanvasOverlay extends BitmapOverlay
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||
| ↳ | [androidx.media3.effect.TextureOverlay](https://developer.android.com/reference/androidx/media3/effect/TextureOverlay) |||
|   | ↳ | [androidx.media3.effect.BitmapOverlay](https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay) ||
|   |   | ↳ | [androidx.media3.effect.CanvasOverlay](https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay) |

Known direct subclasses [LottieOverlay](https://developer.android.com/reference/androidx/media3/effect/lottie/LottieOverlay)

|---|---|
| `https://developer.android.com/reference/androidx/media3/effect/lottie/LottieOverlay` | A `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay` that renders a Lottie animation. |

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/effect/TextOverlay` that is backed by a `https://developer.android.com/reference/android/graphics/Canvas.html`.

Use this class when the size of the drawing `https://developer.android.com/reference/android/graphics/Canvas.html` is known, or when drawing to the entire video size is desied.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#CanvasOverlay(boolean)(boolean useInputFrameSize)` Creates a new `CanvasOverlay`. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#configure(androidx.media3.common.util.Size)(https://developer.android.com/reference/androidx/media3/common/util/Size videoSize)` Set up resources for the overlay given the input video's dimensions. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#getBitmap(long)(long presentationTimeUs)` Returns the overlay bitmap displayed at the specified timestamp. |
| `abstract void` | `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#onDraw(android.graphics.Canvas,long)(https://developer.android.com/reference/android/graphics/Canvas.html canvas, long presentationTimeUs)` Perform custom drawing onto the `https://developer.android.com/reference/android/graphics/Canvas.html`. |
| `void` | `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#release()()` Releases all resources. |
| `void` | `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#setCanvasSize(int,int)(int width, int height)` Sets the size of the `https://developer.android.com/reference/android/graphics/Canvas.html`. |

| ### Inherited methods |
|---|
| From [androidx.media3.effect.BitmapOverlay](https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay) |---|---| | `static https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay` | `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay#createStaticBitmapOverlay(android.graphics.Bitmap)(https://developer.android.com/reference/android/graphics/Bitmap.html overlayBitmap)` Creates a `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay` that shows the `overlayBitmap` in the same position and size throughout the whole video. | | `static https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay` | `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay#createStaticBitmapOverlay(android.graphics.Bitmap,androidx.media3.effect.StaticOverlaySettings)( https://developer.android.com/reference/android/graphics/Bitmap.html overlayBitmap, https://developer.android.com/reference/androidx/media3/effect/StaticOverlaySettings overlaySettings )` Creates a `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay` that shows the `overlayBitmap` in the same `https://developer.android.com/reference/androidx/media3/common/OverlaySettings` throughout the whole video. | | `static https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay` | `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay#createStaticBitmapOverlay(android.content.Context,android.net.Uri,androidx.media3.effect.StaticOverlaySettings)( https://developer.android.com/reference/android/content/Context.html context, https://developer.android.com/reference/android/net/Uri.html overlayBitmapUri, https://developer.android.com/reference/androidx/media3/effect/StaticOverlaySettings overlaySettings )` Creates a `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay` that shows the input at `overlayBitmapUri` with the same `https://developer.android.com/reference/androidx/media3/effect/StaticOverlaySettings` throughout the whole video. | | `int` | `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay#getTextureId(long)(long presentationTimeUs)` Returns the overlay texture identifier displayed at the specified timestamp. | | `https://developer.android.com/reference/androidx/media3/common/util/Size` | `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay#getTextureSize(long)(long presentationTimeUs)` Returns the pixel width and height of the overlay texture displayed at the specified timestamp. | | `float[]` | `https://developer.android.com/reference/androidx/media3/effect/BitmapOverlay#getVertexTransformation(long)(long presentationTimeUs)` Returns a 4x4 OpenGL matrix, controlling how the vertices of the overlay are displayed at the specified timestamp. | |
| From [androidx.media3.effect.TextureOverlay](https://developer.android.com/reference/androidx/media3/effect/TextureOverlay) |---|---| | `https://developer.android.com/reference/androidx/media3/common/OverlaySettings` | `https://developer.android.com/reference/androidx/media3/effect/TextureOverlay#getOverlaySettings(long)(long presentationTimeUs)` Returns the `https://developer.android.com/reference/androidx/media3/common/OverlaySettings` controlling how the overlay is displayed at the specified timestamp. | |

## Public constructors

### CanvasOverlay

```
public CanvasOverlay(boolean useInputFrameSize)
```

Creates a new `CanvasOverlay`.

| Parameters |
|---|---|
| `boolean useInputFrameSize` | Whether to create the `https://developer.android.com/reference/android/graphics/Canvas.html` to match the input frame size, if `false`, `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#setCanvasSize(int,int)` must be set before the first invocation to `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#onDraw(android.graphics.Canvas,long)`. |

## Public methods

### configure

```
public void configure(Size videoSize)
```

Set up resources for the overlay given the input video's dimensions.

This method will be called before drawing the first frame and before drawing subsequent frames with different input dimensions.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/Size videoSize` | The width and height of the input video, in pixels. |

### getBitmap

```
public Bitmap getBitmap(long presentationTimeUs)
```

Returns the overlay bitmap displayed at the specified timestamp.

| Parameters |
|---|---|
| `long presentationTimeUs` | The presentation timestamp of the current frame, in microseconds. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessingException` | If an error occurs while processing or drawing the frame. |

### onDraw

```
public abstract void onDraw(Canvas canvas, long presentationTimeUs)
```

Perform custom drawing onto the `https://developer.android.com/reference/android/graphics/Canvas.html`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/Canvas.html canvas` | The `https://developer.android.com/reference/android/graphics/Canvas.html` to draw onto. |
| `long presentationTimeUs` | The presentation timestamp, in microseconds. |

### release

```
public void release()
```

Releases all resources.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessingException` | If an error occurs while releasing resources. |

### setCanvasSize

```
public void setCanvasSize(int width, int height)
```

Sets the size of the `https://developer.android.com/reference/android/graphics/Canvas.html`.

The default canvas size will be of the same size as the video frame.

The size will be applied on the next invocation of `https://developer.android.com/reference/androidx/media3/effect/CanvasOverlay#onDraw(android.graphics.Canvas,long)`.