# 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
public class BitmapPixelTestUtil
```

<br />

*** ** * ** ***

Utilities for pixel tests.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/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 |
|---|---|
| `static final float` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE()` Maximum allowed average pixel difference between bitmaps generated. |
| `static final float` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE()` Maximum allowed average pixel difference between bitmaps generated using devices. |
| `static final float` | `https://developer.android.com/reference/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. |
| `static final float` | `https://developer.android.com/reference/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 methods |
|---|---|
| `static https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil.ImageBuffer` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#copyByteBufferFromRbga8888Image(android.media.Image)(https://developer.android.com/reference/android/media/Image.html image)` Returns the `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil.ImageBuffer` that is copied from the `https://developer.android.com/reference/android/media/Image.html`'s internal buffer. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#copyRbga8888BitmapToImage(android.graphics.Bitmap,android.media.Image)(https://developer.android.com/reference/android/graphics/Bitmap.html bitmap, https://developer.android.com/reference/android/media/Image.html image)` 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. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapFromFocusedGlFramebuffer(int,int)(int width, int height)` Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` bitmap with the values of the focused OpenGL framebuffer. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapFromGlTexture(androidx.media3.common.GlTextureInfo)(https://developer.android.com/reference/androidx/media3/common/GlTextureInfo 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/androidx/media3/common/GlTextureInfo`. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapFromRgba8888Image(android.media.Image)(https://developer.android.com/reference/android/media/Image.html image)` Returns a bitmap with the same information as the provided alpha/red/green/blue 8-bits per component image. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapFromRgba8888ImageBuffer(androidx.media3.test.utils.BitmapPixelTestUtil.ImageBuffer)( https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil.ImageBuffer imageBuffer )` |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createArgb8888BitmapWithSolidColor(int,int,int)(int width, int height, int color)` Returns a solid `https://developer.android.com/reference/android/graphics/Bitmap.html` with every pixel having the same color. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createFp16BitmapFromFocusedGlFramebuffer(int,int)(int width, int height)` Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#RGBA_F16` bitmap with the values of the focused OpenGL framebuffer. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createFp16BitmapFromGlTexture(androidx.media3.common.GlTextureInfo)(https://developer.android.com/reference/androidx/media3/common/GlTextureInfo 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/androidx/media3/common/GlTextureInfo`. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createFp16BitmapWithSolidColor(int,int,float,float,float)( int width, int height, float r, float g, float b )` 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`. |
| `static int` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createGlTextureFromBitmap(android.graphics.Bitmap)(https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` Creates a `https://developer.android.com/reference/android/opengl/GLES20.html#GL_TEXTURE_2D` with the bitmap's contents. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createGrayscaleBitmapFromYuv420888Image(android.media.Image,android.graphics.Bitmap.Config)( https://developer.android.com/reference/android/media/Image.html image, https://developer.android.com/reference/android/graphics/Bitmap.Config.html bitmapConfig )` Returns a grayscale bitmap from the Luma channel in the `https://developer.android.com/reference/android/graphics/ImageFormat.html#YUV_420_888` image. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#createUnpremultipliedArgb8888BitmapFromFocusedGlFramebuffer(int,int)( int width, int height )` Creates a `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` bitmap with the values of the focused OpenGL framebuffer. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#flipBitmapVertically(android.graphics.Bitmap)(https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` |
| `static float` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceArgb8888(android.graphics.Bitmap,android.graphics.Bitmap,java.lang.String)( https://developer.android.com/reference/android/graphics/Bitmap.html expected, https://developer.android.com/reference/android/graphics/Bitmap.html actual, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html testId )` 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. |
| `static float` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceArgb8888(android.graphics.Bitmap,android.graphics.Bitmap,java.lang.String,java.lang.String)( https://developer.android.com/reference/android/graphics/Bitmap.html expected, https://developer.android.com/reference/android/graphics/Bitmap.html actual, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html testId, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html differencesBitmapPath )` Returns the average difference between the expected and actual bitmaps. |
| `static float` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 29) https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceFp16(android.graphics.Bitmap,android.graphics.Bitmap)( https://developer.android.com/reference/android/graphics/Bitmap.html expected, https://developer.android.com/reference/android/graphics/Bitmap.html actual )` Returns the average difference between the expected and actual bitmaps. |
| `static void` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#maybeSaveTestBitmap(java.lang.String,java.lang.String,android.graphics.Bitmap,java.lang.String)( https://developer.android.com/reference/java/lang/String.html testId, https://developer.android.com/reference/java/lang/String.html bitmapLabel, https://developer.android.com/reference/android/graphics/Bitmap.html bitmap, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html path )` 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()`. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#readBitmap(java.lang.String)(https://developer.android.com/reference/java/lang/String.html assetString)` Reads a bitmap from the specified asset location. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/test/utils/BitmapPixelTestUtil#readBitmapUnpremultipliedAlpha(java.lang.String)(https://developer.android.com/reference/java/lang/String.html assetString)` Reads a bitmap with unpremultiplied alpha from the specified asset location. |

## Constants

### MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE

```
public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE
```

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/androidx/media3/test/utils/BitmapPixelTestUtil#MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE()` if running on physical devices.

### MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE

```
public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE
```

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/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

```
public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_DIFFERENT_DEVICE_FP16 = 0.01f
```

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/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

```
public static final float MAXIMUM_AVERAGE_PIXEL_ABSOLUTE_DIFFERENCE_LUMA = 8.0f
```

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

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

## Public methods

### copyByteBufferFromRbga8888Image

```
public static BitmapPixelTestUtil.ImageBuffer copyByteBufferFromRbga8888Image(Image image)
```

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

### copyRbga8888BitmapToImage

```
public static void copyRbga8888BitmapToImage(Bitmap bitmap, Image image)
```

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

```
public static Bitmap createArgb8888BitmapFromFocusedGlFramebuffer(int width, int height)
```

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/androidx/media3/test/utils/BitmapPixelTestUtil#createUnpremultipliedArgb8888BitmapFromFocusedGlFramebuffer(int,int)` to properly handle alpha.

| Parameters |
|---|---|
| `int width` | The width of the pixel rectangle to read. |
| `int height` | 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/androidx/media3/common/util/GlUtil.GlException` |   |

### createArgb8888BitmapFromGlTexture

```
public static Bitmap createArgb8888BitmapFromGlTexture(GlTextureInfo 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/androidx/media3/common/GlTextureInfo`.

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

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

### createArgb8888BitmapFromRgba8888Image

```
public static Bitmap createArgb8888BitmapFromRgba8888Image(Image image)
```

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

### createArgb8888BitmapFromRgba8888ImageBuffer

```
public static Bitmap createArgb8888BitmapFromRgba8888ImageBuffer(
    BitmapPixelTestUtil.ImageBuffer imageBuffer
)
```

### createArgb8888BitmapWithSolidColor

```
public static Bitmap createArgb8888BitmapWithSolidColor(int width, int height, int color)
```

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

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

### createFp16BitmapFromFocusedGlFramebuffer

```
@RequiresApi(value = 26)
public static Bitmap createFp16BitmapFromFocusedGlFramebuffer(int width, int height)
```

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 |
|---|---|
| `int width` | The width of the pixel rectangle to read. |
| `int height` | 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/androidx/media3/common/util/GlUtil.GlException` |   |

### createFp16BitmapFromGlTexture

```
@RequiresApi(value = 26)
public static Bitmap createFp16BitmapFromGlTexture(GlTextureInfo 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/androidx/media3/common/GlTextureInfo`.

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

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

### createFp16BitmapWithSolidColor

```
@RequiresApi(value = 26)
public static Bitmap createFp16BitmapWithSolidColor(
    int width,
    int height,
    float r,
    float g,
    float b
)
```

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 |
|---|---|
| `int width` | The width of image to create, in pixels. |
| `int height` | The height of image to create, in pixels. |
| `float r` | The red component. |
| `float g` | The green component. |
| `float b` | The blue component. |

### createGlTextureFromBitmap

```
public static int createGlTextureFromBitmap(Bitmap bitmap)
```

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

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

| Returns |
|---|---|
| `int` | The identifier of the newly created texture. |

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

### createGrayscaleBitmapFromYuv420888Image

```
public static Bitmap createGrayscaleBitmapFromYuv420888Image(
    Image image,
    Bitmap.Config bitmapConfig
)
```

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

### createUnpremultipliedArgb8888BitmapFromFocusedGlFramebuffer

```
public static Bitmap createUnpremultipliedArgb8888BitmapFromFocusedGlFramebuffer(
    int width,
    int height
)
```

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 |
|---|---|
| `int width` | The width of the pixel rectangle to read. |
| `int height` | 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/androidx/media3/common/util/GlUtil.GlException` |   |

### flipBitmapVertically

```
public static Bitmap flipBitmapVertically(Bitmap bitmap)
```

### getBitmapAveragePixelAbsoluteDifferenceArgb8888

```
public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888(
    Bitmap expected,
    Bitmap actual,
    @Nullable String testId
)
```

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/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/androidx/media3/test/utils/BitmapPixelTestUtil#getBitmapAveragePixelAbsoluteDifferenceArgb8888(android.graphics.Bitmap,android.graphics.Bitmap,java.lang.String,java.lang.String)` without a specified saved path.

### getBitmapAveragePixelAbsoluteDifferenceArgb8888

```
public static float getBitmapAveragePixelAbsoluteDifferenceArgb8888(
    Bitmap expected,
    Bitmap actual,
    @Nullable String testId,
    @Nullable String differencesBitmapPath
)
```

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 |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html expected` | The expected `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html actual` | The actual `https://developer.android.com/reference/android/graphics/Bitmap.html` produced by the test. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html testId` | 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. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html differencesBitmapPath` | 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 |
|---|---|
| `float` | The average of the maximum absolute pixel-wise differences between the expected and actual bitmaps. |

### getBitmapAveragePixelAbsoluteDifferenceFp16

```
@RequiresApi(value = 29)
public static float getBitmapAveragePixelAbsoluteDifferenceFp16(
    Bitmap expected,
    Bitmap actual
)
```

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 |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html expected` | The expected `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html actual` | The actual `https://developer.android.com/reference/android/graphics/Bitmap.html` produced by the test. |

| Returns |
|---|---|
| `float` | The average of the maximum absolute pixel-wise differences between the expected and actual bitmaps. |

### maybeSaveTestBitmap

```
public static void maybeSaveTestBitmap(
    String testId,
    String bitmapLabel,
    Bitmap bitmap,
    @Nullable String path
)
```

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 |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html testId` | Name of the test that produced the `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `https://developer.android.com/reference/java/lang/String.html bitmapLabel` | Label to identify the bitmap. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html bitmap` | The `https://developer.android.com/reference/android/graphics/Bitmap.html` to save. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/String.html path` | 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

```
public static Bitmap readBitmap(String assetString)
```

Reads a bitmap from the specified asset location.

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html assetString` | 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

```
public static Bitmap readBitmapUnpremultipliedAlpha(String assetString)
```

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

| Parameters |
|---|---|
| `https://developer.android.com/reference/java/lang/String.html assetString` | 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. |