# TextureBitmapReader

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

*** ** * ** ***


```
@UnstableApi
public final class TextureBitmapReader implements VideoFrameProcessorTestRunner.BitmapReader
```

<br />

*** ** * ** ***

Reads from an OpenGL texture. Only for use on physical devices.

For images with alpha, this method incorrectly marks the output Bitmap as `https://developer.android.com/reference/android/graphics/Bitmap.html#isPremultiplied()`, even though OpenGL typically outputs only non-premultiplied alpha.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#TextureBitmapReader()()` |

| ### Public methods |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#getBitmap()()` Returns the output `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#getBitmapAtPresentationTimeUs(long)(long presentationTimeUs)` |
| `https://developer.android.com/reference/java/util/Set.html<https://developer.android.com/reference/java/lang/Long.html>` | `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#getOutputTimestamps()()` Returns the timestamps in the order they were added. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/view/Surface.html` | `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#getSurface(int,int,boolean)( int width, int height, boolean useHighPrecisionColorComponents )` Returns the `https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessor` output `https://developer.android.com/reference/android/view/Surface.html`, if one is needed. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#readBitmap(androidx.media3.common.GlTextureInfo,long)(https://developer.android.com/reference/androidx/media3/common/GlTextureInfo outputTexture, long presentationTimeUs)` Reads the given `outputTexture`. |
| `void` | `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#readBitmapUnpremultipliedAlpha(androidx.media3.common.GlTextureInfo,long)( https://developer.android.com/reference/androidx/media3/common/GlTextureInfo outputTexture, long presentationTimeUs )` Reads the given `outputTexture` as one with unpremultiplied alpha. |

## Public constructors

### TextureBitmapReader

```
public TextureBitmapReader()
```

## Public methods

### getBitmap

```
public Bitmap getBitmap()
```

Returns the output `https://developer.android.com/reference/android/graphics/Bitmap.html`.

### getBitmapAtPresentationTimeUs

```
public Bitmap getBitmapAtPresentationTimeUs(long presentationTimeUs)
```

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | The output `https://developer.android.com/reference/android/graphics/Bitmap.html` at a given `presentationTimeUs`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException.html` | If no such bitmap is produced. |

### getOutputTimestamps

```
public Set<Long> getOutputTimestamps()
```

Returns the timestamps in the order they were added.

### getSurface

```
public @Nullable Surface getSurface(
    int width,
    int height,
    boolean useHighPrecisionColorComponents
)
```

Returns the `https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessor` output `https://developer.android.com/reference/android/view/Surface.html`, if one is needed.

### readBitmap

```
public void readBitmap(GlTextureInfo outputTexture, long presentationTimeUs)
```

Reads the given `outputTexture`.

The read result can be fetched by calling `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#getBitmapAtPresentationTimeUs(long)` or `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#getBitmap()`.

This implementation incorrectly marks the output Bitmap as `https://developer.android.com/reference/android/graphics/Bitmap.html#isPremultiplied()`, even though OpenGL typically outputs only non-premultiplied alpha. Use `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#readBitmapUnpremultipliedAlpha(androidx.media3.common.GlTextureInfo,long)` to properly handle alpha.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessingException` |   |

### readBitmapUnpremultipliedAlpha

```
public void readBitmapUnpremultipliedAlpha(
    GlTextureInfo outputTexture,
    long presentationTimeUs
)
```

Reads the given `outputTexture` as one with unpremultiplied alpha.

The read result can be fetched by calling `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#getBitmapAtPresentationTimeUs(long)` or `https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader#getBitmap()`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/VideoFrameProcessingException` |   |