# BitmapPixelTestUtil

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/BitmapPixelTestUtil.java+class:androidx.media3.test.utils.BitmapPixelTestUtil)

*** ** * ** ***


```
@UnstableApi
class BitmapPixelTestUtil
```

<br />

*** ** * ** ***

Utilities for pixel tests.

## Summary

| ### Nested types |
|---|
| `class https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil.ImageBuffer` Represents a `https://developer.android.com/reference/java/nio/ByteBuffer.html` read from an `https://developer.android.com/reference/android/media/Image.html`. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE()` Maximum allowed average pixel difference between bitmaps generated. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE()` Maximum allowed average pixel difference between bitmaps generated using devices. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE_FP16() = 0.01f` Maximum allowed average pixel difference between bitmaps with 16-bit primaries generated using devices. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_LUMA() = 8.0f` Maximum allowed average pixel difference between bitmaps generated from luma values. |

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil.ImageBuffer!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#copyByteBufferFromRbga8888Image(android.media.Image)(image: https://developer.android.com/reference/android/media/Image.html!)` Returns the `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil.ImageBuffer` that is copied from the `https://developer.android.com/reference/android/media/Image.html`'s internal buffer. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#copyRbga8888BitmapToImage(android.graphics.Bitmap,android.media.Image)(bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!, image: https://developer.android.com/reference/android/media/Image.html!)` Copies image data from the specified `https://developer.android.com/reference/android/graphics/Bitmap.html` into the `https://developer.android.com/reference/android/media/Image.html`, which must be an `https://developer.android.com/reference/android/graphics/PixelFormat.html#RGBA_8888` image. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapFromFocusedGlFramebuffer(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)` Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` bitmap with the values of the focused OpenGL framebuffer. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapFromGlTexture(androidx.media3.common.GlTextureInfo)(glTextureInfo: https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo!)` Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` bitmap with the values of the specified `https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo`. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapFromRgba8888Image(android.media.Image)(image: https://developer.android.com/reference/android/media/Image.html!)` Returns a bitmap with the same information as the provided alpha/red/green/blue 8-bits per component image. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapFromRgba8888ImageBuffer(androidx.media3.test.utils.BitmapPixelTestUtil.ImageBuffer)( imageBuffer: https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil.ImageBuffer! )` |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapWithSolidColor(int,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, color: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Returns a solid `https://developer.android.com/reference/android/graphics/Bitmap.html` with every pixel having the same color. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createFp16BitmapFromFocusedGlFramebuffer(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)` Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#RGBA_F16` bitmap with the values of the focused OpenGL framebuffer. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createFp16BitmapFromGlTexture(androidx.media3.common.GlTextureInfo)(glTextureInfo: https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo!)` Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#RGBA_F16` bitmap with the values of the specified `https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo`. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createFp16BitmapWithSolidColor(int,int,float,float,float)( width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, r: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, g: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, b: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` Returns a solid `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#RGBA_F16``https://developer.android.com/reference/android/graphics/Bitmap.html` with every pixel having the same color and an alpha value of `1.0f`. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createGlTextureFromBitmap(android.graphics.Bitmap)(bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!)` Creates a `https://developer.android.com/reference/android/opengl/GLES20.html#GL_TEXTURE_2D` with the bitmap's contents. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createGrayscaleBitmapFromYuv420888Image(android.media.Image,android.graphics.Bitmap.Config)( image: https://developer.android.com/reference/android/media/Image.html!, bitmapConfig: https://developer.android.com/reference/android/graphics/Bitmap.Config.html! )` Returns a grayscale bitmap from the Luma channel in the `https://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888` image. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createUnpremultipliedArgb8888BitmapFromFocusedGlFramebuffer(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 )` Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` bitmap with the values of the focused OpenGL framebuffer. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#flipBitmapVertically(android.graphics.Bitmap)(bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!)` |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceArgb8888(android.graphics.Bitmap,android.graphics.Bitmap,java.lang.String)( expected: https://developer.android.com/reference/android/graphics/Bitmap.html!, actual: https://developer.android.com/reference/android/graphics/Bitmap.html!, testId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? )` Returns the average difference between the expected and actual bitmaps, calculated using the maximum difference across all color channels for each pixel, then divided by the total number of pixels in the image, without saving the difference bitmap. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceArgb8888(android.graphics.Bitmap,android.graphics.Bitmap,java.lang.String,java.lang.String)( expected: https://developer.android.com/reference/android/graphics/Bitmap.html!, actual: https://developer.android.com/reference/android/graphics/Bitmap.html!, testId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?, differencesBitmapPath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? )` Returns the average difference between the expected and actual bitmaps. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceFp16(android.graphics.Bitmap,android.graphics.Bitmap)( expected: https://developer.android.com/reference/android/graphics/Bitmap.html!, actual: https://developer.android.com/reference/android/graphics/Bitmap.html! )` Returns the average difference between the expected and actual bitmaps. |
| `java-static https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#maybeSaveTestBitmap(java.lang.String,java.lang.String,android.graphics.Bitmap,java.lang.String)( testId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, bitmapLabel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!, path: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html? )` Tries to save the `https://developer.android.com/reference/android/graphics/Bitmap.html` as a PNG to the `<path>`, and if not provided, tries to save to the `https://developer.android.com/reference/android/content/Context.html#getCacheDir()`. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#readBitmap(java.lang.String)(assetString: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Reads a bitmap from the specified asset location. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#readBitmapUnpremultipliedAlpha(java.lang.String)(assetString: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Reads a bitmap with unpremultiplied alpha from the specified asset location. |

## Constants

### MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE

```
const val MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE: Float
```

Maximum allowed average pixel difference between bitmaps generated.

This value is for for 8-bit primaries in pixel difference-based tests.

The value is chosen so that differences in decoder behavior across devices don't affect whether the test passes, but substantial distortions introduced by changes in tested components will cause the test to fail.

When the difference is close to the threshold, manually inspect expected/actual bitmaps to confirm failure, as it's possible this is caused by a difference in the codec or graphics implementation as opposed to an issue in the tested component.

The value is the same as `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE()` if running on physical devices.

### MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE

```
const val MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE: Float
```

Maximum allowed average pixel difference between bitmaps generated using devices.

This value is for for 8-bit primaries in pixel difference-based tests.

The value is chosen so that differences in decoder behavior across devices don't affect whether the test passes, but substantial distortions introduced by changes in tested components will cause the test to fail.

When the difference is close to the threshold, manually inspect expected/actual bitmaps to confirm failure, as it's possible this is caused by a difference in the codec or graphics implementation as opposed to an issue in the tested component.

This value is larger than `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE()` to support the larger variance in decoder outputs between different physical devices and emulators.

### MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE_FP16

```
const val MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE_FP16 = 0.01f: Float
```

Maximum allowed average pixel difference between bitmaps with 16-bit primaries generated using devices.

The value is chosen so that differences in decoder behavior across devices in pixel difference-based tests don't affect whether the test passes, but substantial distortions introduced by changes in tested components will cause the test to fail.

When the difference is close to the threshold, manually inspect expected/actual bitmaps to confirm failure, as it's possible this is caused by a difference in the codec or graphics implementation as opposed to an issue in the tested component.

This value is larger than `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE()` to support the larger variance in decoder outputs between different physical devices and emulators.

### MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_LUMA

```
const val MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_LUMA = 8.0f: Float
```

Maximum allowed average pixel difference between bitmaps generated from luma values.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE()` |   |

## Public functions

### copyByteBufferFromRbga8888Image

```
java-static fun copyByteBufferFromRbga8888Image(image: Image!): BitmapPixelTestUtil.ImageBuffer!
```

Returns the `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil.ImageBuffer` that is copied from the `https://developer.android.com/reference/android/media/Image.html`'s internal buffer.

### copyRbga8888BitmapToImage

```
java-static fun copyRbga8888BitmapToImage(bitmap: Bitmap!, image: Image!): Unit
```

Copies image data from the specified `https://developer.android.com/reference/android/graphics/Bitmap.html` into the `https://developer.android.com/reference/android/media/Image.html`, which must be an `https://developer.android.com/reference/android/graphics/PixelFormat.html#RGBA_8888` image.

### createArgb8888BitmapFromFocusedGlFramebuffer

```
java-static fun createArgb8888BitmapFromFocusedGlFramebuffer(width: Int, height: Int): Bitmap!
```

Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` bitmap with the values of the focused OpenGL framebuffer.

This method may block until any previously called OpenGL commands are complete.

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. Use `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#createUnpremultipliedArgb8888BitmapFromFocusedGlFramebuffer(int,int)` to properly handle alpha.

| Parameters |
|---|---|
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The width of the pixel rectangle to read. |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The height of the pixel rectangle to read. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html!` | A `https://developer.android.com/reference/android/graphics/Bitmap.html` with the framebuffer's values. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### createArgb8888BitmapFromGlTexture

```
java-static fun createArgb8888BitmapFromGlTexture(glTextureInfo: GlTextureInfo!): Bitmap!
```

Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` bitmap with the values of the specified `https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo`.

Must be called with an active OpenGL context on the current thread.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### createArgb8888BitmapFromRgba8888Image

```
java-static fun createArgb8888BitmapFromRgba8888Image(image: Image!): Bitmap!
```

Returns a bitmap with the same information as the provided alpha/red/green/blue 8-bits per component image.

### createArgb8888BitmapFromRgba8888ImageBuffer

```
java-static fun createArgb8888BitmapFromRgba8888ImageBuffer(
    imageBuffer: BitmapPixelTestUtil.ImageBuffer!
): Bitmap!
```

### createArgb8888BitmapWithSolidColor

```
java-static fun createArgb8888BitmapWithSolidColor(width: Int, height: Int, color: Int): Bitmap!
```

Returns a solid `https://developer.android.com/reference/android/graphics/Bitmap.html` with every pixel having the same color.

| Parameters |
|---|---|
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The width of image to create, in pixels. |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The height of image to create, in pixels. |
| `color: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | An RGBA color created by `https://developer.android.com/reference/android/graphics/Color.html`. |

### createFp16BitmapFromFocusedGlFramebuffer

```
@RequiresApi(value = 26)
java-static fun createFp16BitmapFromFocusedGlFramebuffer(width: Int, height: Int): Bitmap!
```

Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#RGBA_F16` bitmap with the values of the focused OpenGL framebuffer.

This method may block until any previously called OpenGL commands are complete.

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. Call `https://developer.android.com/reference/android/graphics/Bitmap.html#setPremultiplied(boolean)` with `false` on the output bitmap to properly handle alpha.

| Parameters |
|---|---|
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The width of the pixel rectangle to read. |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The height of the pixel rectangle to read. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html!` | A `https://developer.android.com/reference/android/graphics/Bitmap.html` with the framebuffer's values. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### createFp16BitmapFromGlTexture

```
@RequiresApi(value = 26)
java-static fun createFp16BitmapFromGlTexture(glTextureInfo: GlTextureInfo!): Bitmap!
```

Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#RGBA_F16` bitmap with the values of the specified `https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo`.

Must be called with an active OpenGL context on the current thread.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### createFp16BitmapWithSolidColor

```
@RequiresApi(value = 26)
java-static fun createFp16BitmapWithSolidColor(
    width: Int,
    height: Int,
    r: Float,
    g: Float,
    b: Float
): Bitmap!
```

Returns a solid `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#RGBA_F16``https://developer.android.com/reference/android/graphics/Bitmap.html` with every pixel having the same color and an alpha value of `1.0f`.

| Parameters |
|---|---|
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The width of image to create, in pixels. |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The height of image to create, in pixels. |
| `r: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The red component. |
| `g: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The green component. |
| `b: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The blue component. |

### createGlTextureFromBitmap

```
java-static fun createGlTextureFromBitmap(bitmap: Bitmap!): Int
```

Creates a `https://developer.android.com/reference/android/opengl/GLES20.html#GL_TEXTURE_2D` with the bitmap's contents.

| Parameters |
|---|---|
| `bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!` | A `https://developer.android.com/reference/android/graphics/Bitmap.html`. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The identifier of the newly created texture. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### createGrayscaleBitmapFromYuv420888Image

```
java-static fun createGrayscaleBitmapFromYuv420888Image(
    image: Image!,
    bitmapConfig: Bitmap.Config!
): Bitmap!
```

Returns a grayscale bitmap from the Luma channel in the `https://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888` image.

### createUnpremultipliedArgb8888BitmapFromFocusedGlFramebuffer

```
java-static fun createUnpremultipliedArgb8888BitmapFromFocusedGlFramebuffer(
    width: Int,
    height: Int
): Bitmap!
```

Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` bitmap with the values of the focused OpenGL framebuffer.

This method may block until any previously called OpenGL commands are complete.

| Parameters |
|---|---|
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The width of the pixel rectangle to read. |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The height of the pixel rectangle to read. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html!` | A `https://developer.android.com/reference/android/graphics/Bitmap.html` with the framebuffer's values. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### flipBitmapVertically

```
java-static fun flipBitmapVertically(bitmap: Bitmap!): Bitmap!
```

### getBitmapAveragePixelAbsoluteDifferenceArgb8888

```
java-static fun getBitmapAveragePixelAbsoluteDifferenceArgb8888(
    expected: Bitmap!,
    actual: Bitmap!,
    testId: String?
): Float
```

Returns the average difference between the expected and actual bitmaps, calculated using the maximum difference across all color channels for each pixel, then divided by the total number of pixels in the image, without saving the difference bitmap. See `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceArgb8888(android.graphics.Bitmap,android.graphics.Bitmap,java.lang.String,java.lang.String)`.

This method is the overloaded version of `https://developer.android.com/reference/kotlin/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceArgb8888(android.graphics.Bitmap,android.graphics.Bitmap,java.lang.String,java.lang.String)` without a specified saved path.

### getBitmapAveragePixelAbsoluteDifferenceArgb8888

```
java-static fun getBitmapAveragePixelAbsoluteDifferenceArgb8888(
    expected: Bitmap!,
    actual: Bitmap!,
    testId: String?,
    differencesBitmapPath: String?
): Float
```

Returns the average difference between the expected and actual bitmaps.

Calculated using the maximum difference across all color channels for each pixel, then divided by the total number of pixels in the image. Bitmap resolutions must match and must use configuration `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888`.

Tries to save a difference bitmap between expected and actual bitmaps.

| Parameters |
|---|---|
| `expected: https://developer.android.com/reference/android/graphics/Bitmap.html!` | The expected `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `actual: https://developer.android.com/reference/android/graphics/Bitmap.html!` | The actual `https://developer.android.com/reference/android/graphics/Bitmap.html` produced by the test. |
| `testId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | The name of the test that produced the `https://developer.android.com/reference/android/graphics/Bitmap.html`, or `null` if the differences bitmap should not be saved to cache. |
| `differencesBitmapPath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | Folder path for the produced pixel-wise difference `https://developer.android.com/reference/android/graphics/Bitmap.html` to be saved in or `null` if the assumed default save path should be used. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The average of the maximum absolute pixel-wise differences between the expected and actual bitmaps. |

### getBitmapAveragePixelAbsoluteDifferenceFp16

```
@RequiresApi(value = 29)
java-static fun getBitmapAveragePixelAbsoluteDifferenceFp16(
    expected: Bitmap!,
    actual: Bitmap!
): Float
```

Returns the average difference between the expected and actual bitmaps.

Calculated using the maximum difference across all color channels for each pixel, then divided by the total number of pixels in the image. Bitmap resolutions must match and must use configuration `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#RGBA_F16`.

| Parameters |
|---|---|
| `expected: https://developer.android.com/reference/android/graphics/Bitmap.html!` | The expected `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `actual: https://developer.android.com/reference/android/graphics/Bitmap.html!` | The actual `https://developer.android.com/reference/android/graphics/Bitmap.html` produced by the test. |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The average of the maximum absolute pixel-wise differences between the expected and actual bitmaps. |

### maybeSaveTestBitmap

```
java-static fun maybeSaveTestBitmap(
    testId: String!,
    bitmapLabel: String!,
    bitmap: Bitmap!,
    path: String?
): Unit
```

Tries to save the `https://developer.android.com/reference/android/graphics/Bitmap.html` as a PNG to the `<path>`, and if not provided, tries to save to the `https://developer.android.com/reference/android/content/Context.html#getCacheDir()`.

File name will be `<testId>_<bitmapLabel>.png`. If the file failed to write, any `https://developer.android.com/reference/java/io/IOException.html` will be caught and logged. The path will be logged regardless of success.

| Parameters |
|---|---|
| `testId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | Name of the test that produced the `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `bitmapLabel: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | Label to identify the bitmap. |
| `bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!` | The `https://developer.android.com/reference/android/graphics/Bitmap.html` to save. |
| `path: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html?` | Folder path for the supplied `https://developer.android.com/reference/android/graphics/Bitmap.html` to be saved in or `null` if the `https://developer.android.com/reference/android/content/Context.html#getCacheDir()` should be saved in. |

### readBitmap

```
java-static fun readBitmap(assetString: String!): Bitmap!
```

Reads a bitmap from the specified asset location.

| Parameters |
|---|---|
| `assetString: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | Relative path to the asset within the assets directory. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html!` | A `https://developer.android.com/reference/android/graphics/Bitmap.html`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If the bitmap can't be read. |

### readBitmapUnpremultipliedAlpha

```
java-static fun readBitmapUnpremultipliedAlpha(assetString: String!): Bitmap!
```

Reads a bitmap with unpremultiplied alpha from the specified asset location.

| Parameters |
|---|---|
| `assetString: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | Relative path to the asset within the assets directory. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html!` | A `https://developer.android.com/reference/android/graphics/Bitmap.html`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | If the bitmap can't be read. |