BitmapOverlay


@UnstableApi
public abstract class BitmapOverlay extends TextureOverlay

Known direct subclasses
DrawableOverlay

Creates a TextureOverlay from Drawable.

TextOverlay

Creates a TextureOverlay from text.


Creates TextureOverlays from Bitmaps.

Useful for overlaying images and animated images (e.g. GIFs).

Summary

Public constructors

Public methods

static BitmapOverlay

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

static BitmapOverlay
createStaticBitmapOverlay(
    Bitmap overlayBitmap,
    OverlaySettings overlaySettings
)

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

static BitmapOverlay
createStaticBitmapOverlay(
    Context context,
    Uri overlayBitmapUri,
    OverlaySettings overlaySettings
)

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

abstract Bitmap
getBitmap(long presentationTimeUs)

Returns the overlay bitmap displayed at the specified timestamp.

int
getTextureId(long presentationTimeUs)

Returns the overlay texture identifier displayed at the specified timestamp.

Size
getTextureSize(long presentationTimeUs)

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

float[]
getVertexTransformation(long presentationTimeUs)

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

void

Releases all resources.

Inherited methods

From androidx.media3.effect.TextureOverlay
void
configure(Size videoSize)

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

OverlaySettings
getOverlaySettings(long presentationTimeUs)

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

Public constructors

BitmapOverlay

public BitmapOverlay()

Public methods

createStaticBitmapOverlay

public static BitmapOverlay createStaticBitmapOverlay(Bitmap overlayBitmap)

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

Parameters
Bitmap overlayBitmap

The bitmap to overlay on the video.

createStaticBitmapOverlay

public static BitmapOverlay createStaticBitmapOverlay(
    Bitmap overlayBitmap,
    OverlaySettings overlaySettings
)

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

Parameters
Bitmap overlayBitmap

The bitmap to overlay on the video.

OverlaySettings overlaySettings

The OverlaySettings configuring how the overlay is displayed on the frames.

createStaticBitmapOverlay

public static BitmapOverlay createStaticBitmapOverlay(
    Context context,
    Uri overlayBitmapUri,
    OverlaySettings overlaySettings
)

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

Parameters
Context context

The Context.

Uri overlayBitmapUri

The Uri pointing to the resource to be converted into a bitmap.

OverlaySettings overlaySettings

The OverlaySettings configuring how the overlay is displayed on the frames.

getBitmap

public abstract 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
androidx.media3.common.VideoFrameProcessingException

If an error occurs while processing or drawing the frame.

getTextureId

public int getTextureId(long presentationTimeUs)

Returns the overlay texture identifier displayed at the specified timestamp.

Parameters
long presentationTimeUs

The presentation timestamp of the current frame, in microseconds.

Throws
androidx.media3.common.VideoFrameProcessingException

If an error occurs while processing or drawing the frame.

getTextureSize

public Size getTextureSize(long presentationTimeUs)

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

This method must be called after #getTextureId(long).

Gets the width and height of the cached bitmap.

Parameters
long presentationTimeUs

The presentation timestamp of the current frame, in microseconds.

getVertexTransformation

public float[] getVertexTransformation(long presentationTimeUs)

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

Applied before #getOverlaySettings overlay settings.

Flips the overlay vertically to convert between Android and OpenGL texture coordinate systems.

release

public void release()

Releases all resources.

Throws
androidx.media3.common.VideoFrameProcessingException

If an error occurs while releasing resources.