CanvasOverlay


@UnstableApi
abstract class CanvasOverlay : BitmapOverlay


A TextOverlay that is backed by a Canvas.

Use this class when the size of the drawing Canvas is known, or when drawing to the entire video size is desied.

Summary

Public constructors

CanvasOverlay(useInputFrameSize: Boolean)

Creates a new CanvasOverlay.

Public functions

Unit
configure(videoSize: Size!)

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

Bitmap!
getBitmap(presentationTimeUs: Long)

Returns the overlay bitmap displayed at the specified timestamp.

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

Perform custom drawing onto the Canvas.

Unit

Releases all resources.

Unit
setCanvasSize(width: Int, height: Int)

Sets the size of the Canvas.

Inherited functions

From androidx.media3.effect.BitmapOverlay
java-static BitmapOverlay!

Creates a BitmapOverlay that shows the overlayBitmap in the same position and size throughout the whole video.

java-static BitmapOverlay!
createStaticBitmapOverlay(
    overlayBitmap: Bitmap!,
    overlaySettings: StaticOverlaySettings!
)

Creates a BitmapOverlay that shows the overlayBitmap in the same throughout the whole video.

java-static BitmapOverlay!
createStaticBitmapOverlay(
    context: Context!,
    overlayBitmapUri: Uri!,
    overlaySettings: StaticOverlaySettings!
)

Creates a BitmapOverlay that shows the input at overlayBitmapUri with the same StaticOverlaySettings throughout the whole video.

Int
getTextureId(presentationTimeUs: Long)

Returns the overlay texture identifier displayed at the specified timestamp.

Size!
getTextureSize(presentationTimeUs: Long)

Returns the pixel width and height of the overlay texture displayed at the specified timestamp.

FloatArray<Float>!
getVertexTransformation(presentationTimeUs: Long)

Returns a 4x4 OpenGL matrix, controlling how the vertices of the overlay are displayed at the specified timestamp.

From androidx.media3.effect.TextureOverlay
OverlaySettings!
getOverlaySettings(presentationTimeUs: Long)

Returns the OverlaySettings controlling how the overlay is displayed at the specified timestamp.

Public constructors

CanvasOverlay

CanvasOverlay(useInputFrameSize: Boolean)

Creates a new CanvasOverlay.

Parameters
useInputFrameSize: Boolean

Whether to create the Canvas to match the input frame size, if false, setCanvasSize must be set before the first invocation to onDraw.

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: 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: Long

The presentation timestamp of the current frame, in microseconds.

Throws
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 Canvas.

Parameters
canvas: Canvas!

The Canvas to draw onto.

presentationTimeUs: Long

The presentation timestamp, in microseconds.

release

fun release(): Unit

Releases all resources.

Throws
androidx.media3.common.VideoFrameProcessingException

If an error occurs while releasing resources.

setCanvasSize

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

Sets the size of the Canvas.

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

The size will be applied on the next invocation of onDraw.