# TextureBitmapReader

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/media3/test/utils/TextureBitmapReader "View this page in Java")

<br />

```
@UnstableApi
class TextureBitmapReader : 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[premultiplied](https://developer.android.com/reference/android/graphics/Bitmap.html#isPremultiplied()), even though OpenGL typically outputs only non-premultiplied alpha.

## Summary

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

|                                                                                                                                 ### Public functions                                                                                                                                  |
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)`!`                                                                                                                                                                                                     | [getBitmap](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/TextureBitmapReader#getBitmap())`()` Returns the output[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html).                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| [Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html)`!`                                                                                                                                                                                                     | [getBitmapAtPresentationTimeUs](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/TextureBitmapReader#getBitmapAtPresentationTimeUs(long))`(presentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)`                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `(`[Mutable](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-set/index.html)`)`[Set](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-set/index.html)`<`[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`!>!` | [getOutputTimestamps](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/TextureBitmapReader#getOutputTimestamps())`()` Returns the timestamps in the order they were added.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                        |
| [Surface](https://developer.android.com/reference/android/view/Surface.html)`?`                                                                                                                                                                                                       | [getSurface](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/TextureBitmapReader#getSurface(int,int,boolean))`(` ` width: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` height: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`,` ` useHighPrecisionColorComponents: `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) `)` Returns the[VideoFrameProcessor](https://developer.android.com/reference/kotlin/androidx/media3/common/VideoFrameProcessor)output[Surface](https://developer.android.com/reference/android/view/Surface.html), if one is needed. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                         | [readBitmap](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/TextureBitmapReader#readBitmap(androidx.media3.common.GlTextureInfo,long))`(outputTexture: `[GlTextureInfo](https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo)`!, presentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)`)` Reads the given`outputTexture`.                                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                                                                                                                                                                                                         | [readBitmapUnpremultipliedAlpha](https://developer.android.com/reference/kotlin/androidx/media3/test/utils/TextureBitmapReader#readBitmapUnpremultipliedAlpha(androidx.media3.common.GlTextureInfo,long))`(` ` outputTexture: `[GlTextureInfo](https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo)`!,` ` presentationTimeUs: `[Long](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html) `)` Reads the given`outputTexture`as one with unpremultiplied alpha.                                                                                                                                                                          |

## Public constructors

### TextureBitmapReader

```
TextureBitmapReader()
```  

## Public functions

### getBitmap

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

Returns the output[Bitmap](https://developer.android.com/reference/android/graphics/Bitmap.html).  

### getBitmapAtPresentationTimeUs

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

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

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

### getOutputTimestamps

```
fun getOutputTimestamps(): (Mutable)Set<Long!>!
```

Returns the timestamps in the order they were added.  

### getSurface

```
fun getSurface(
    width: Int,
    height: Int,
    useHighPrecisionColorComponents: Boolean
): Surface?
```

Returns the[VideoFrameProcessor](https://developer.android.com/reference/kotlin/androidx/media3/common/VideoFrameProcessor)output[Surface](https://developer.android.com/reference/android/view/Surface.html), if one is needed.  

### readBitmap

```
fun readBitmap(outputTexture: GlTextureInfo!, presentationTimeUs: Long): Unit
```

Reads the given`outputTexture`.

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

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

|                                                                           Throws                                                                            |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [androidx.media3.common.VideoFrameProcessingException](https://developer.android.com/reference/kotlin/androidx/media3/common/VideoFrameProcessingException) |   |

### readBitmapUnpremultipliedAlpha

```
fun readBitmapUnpremultipliedAlpha(
    outputTexture: GlTextureInfo!,
    presentationTimeUs: Long
): Unit
```

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

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

|                                                                           Throws                                                                            |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [androidx.media3.common.VideoFrameProcessingException](https://developer.android.com/reference/kotlin/androidx/media3/common/VideoFrameProcessingException) |   |