# 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)

*** ** * ** ***

<br />

```
@UnstableApi
abstract class CanvasOverlay : BitmapOverlay
```

<br />

|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) ||||
| ↳ | [androidx.media3.effect.TextureOverlay](https://developer.android.com/reference/kotlin/androidx/media3/effect/TextureOverlay) |||
|   | ↳ | [androidx.media3.effect.BitmapOverlay](https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay) ||
|   |   | ↳ | [androidx.media3.effect.CanvasOverlay](https://developer.android.com/reference/kotlin/androidx/media3/effect/CanvasOverlay) |

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

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

*** ** * ** ***

A `https://developer.android.com/reference/kotlin/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/kotlin/androidx/media3/effect/CanvasOverlay#CanvasOverlay(boolean)(useInputFrameSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Creates a new `CanvasOverlay`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/CanvasOverlay#configure(androidx.media3.common.util.Size)(videoSize: https://developer.android.com/reference/kotlin/androidx/media3/common/util/Size!)` 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/kotlin/androidx/media3/effect/CanvasOverlay#getBitmap(long)(presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Returns the overlay bitmap displayed at the specified timestamp. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/CanvasOverlay#onDraw(android.graphics.Canvas,long)(canvas: https://developer.android.com/reference/android/graphics/Canvas.html!, presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Perform custom drawing onto the `https://developer.android.com/reference/android/graphics/Canvas.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/CanvasOverlay#release()()` Releases all resources. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/CanvasOverlay#setCanvasSize(int,int)(width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets the size of the `https://developer.android.com/reference/android/graphics/Canvas.html`. |

### Inherited functions

From [androidx.media3.effect.BitmapOverlay](https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay) `java-static https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay!` `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay#createStaticBitmapOverlay(android.graphics.Bitmap)(overlayBitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!)`

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay` that shows the `overlayBitmap` in the same position and size throughout the whole video.
`java-static https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay!` `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay#createStaticBitmapOverlay(android.graphics.Bitmap,androidx.media3.effect.StaticOverlaySettings)(

overlayBitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!,

overlaySettings: https://developer.android.com/reference/kotlin/androidx/media3/effect/StaticOverlaySettings!

)`

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay` that shows the `overlayBitmap` in the same `https://developer.android.com/reference/kotlin/androidx/media3/common/OverlaySettings` throughout the whole video.
`java-static https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay!` `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay#createStaticBitmapOverlay(android.content.Context,android.net.Uri,androidx.media3.effect.StaticOverlaySettings)(

context: https://developer.android.com/reference/android/content/Context.html!,

overlayBitmapUri: https://developer.android.com/reference/android/net/Uri.html!,

overlaySettings: https://developer.android.com/reference/kotlin/androidx/media3/effect/StaticOverlaySettings!

)`

Creates a `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay` that shows the input at `overlayBitmapUri` with the same `https://developer.android.com/reference/kotlin/androidx/media3/effect/StaticOverlaySettings` throughout the whole video.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay#getTextureId(long)(presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`

Returns the overlay texture identifier displayed at the specified timestamp.
`https://developer.android.com/reference/kotlin/androidx/media3/common/util/Size!` `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay#getTextureSize(long)(presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`

Returns the pixel width and height of the overlay texture displayed at the specified timestamp.
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>!` `https://developer.android.com/reference/kotlin/androidx/media3/effect/BitmapOverlay#getVertexTransformation(long)(presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`

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/kotlin/androidx/media3/effect/TextureOverlay) `https://developer.android.com/reference/kotlin/androidx/media3/common/OverlaySettings!` `https://developer.android.com/reference/kotlin/androidx/media3/effect/TextureOverlay#getOverlaySettings(long)(presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/common/OverlaySettings` controlling how the overlay is displayed at the specified timestamp.

## Public constructors

### CanvasOverlay

```
CanvasOverlay(useInputFrameSize: Boolean)
```

Creates a new `CanvasOverlay`.

| Parameters |
|---|---|
| `useInputFrameSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | 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/kotlin/androidx/media3/effect/CanvasOverlay#setCanvasSize(int,int)` must be set before the first invocation to `https://developer.android.com/reference/kotlin/androidx/media3/effect/CanvasOverlay#onDraw(android.graphics.Canvas,long)`. |

## Public functions

### configure

```
fun configure(videoSize: Size!): Unit
```

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 |
|---|---|
| `videoSize: https://developer.android.com/reference/kotlin/androidx/media3/common/util/Size!` | The width and height of the input video, in pixels. |

### getBitmap

```
fun getBitmap(presentationTimeUs: Long): Bitmap!
```

Returns the overlay bitmap displayed at the specified timestamp.

| Parameters |
|---|---|
| `presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The presentation timestamp of the current frame, in microseconds. |

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

### onDraw

```
abstract fun onDraw(canvas: Canvas!, presentationTimeUs: Long): Unit
```

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

| Parameters |
|---|---|
| `canvas: https://developer.android.com/reference/android/graphics/Canvas.html!` | The `https://developer.android.com/reference/android/graphics/Canvas.html` to draw onto. |
| `presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The presentation timestamp, in microseconds. |

### release

```
fun release(): Unit
```

Releases all resources.

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

### setCanvasSize

```
fun setCanvasSize(width: Int, height: Int): Unit
```

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/kotlin/androidx/media3/effect/CanvasOverlay#onDraw(android.graphics.Canvas,long)`.