# BitmapUtil

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

*** ** * ** ***

<br />

```
@UnstableApi
class BitmapUtil
```

<br />

*** ** * ** ***

Utility methods for `https://developer.android.com/reference/android/graphics/Bitmap.html` instances.

## Summary

| ### Public functions |
|---|---|
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/BitmapUtil#decode(byte[],int,android.graphics.BitmapFactory.Options,int)( data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!, length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, options: https://developer.android.com/reference/android/graphics/BitmapFactory.Options.html?, maximumOutputDimension: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Decodes a `https://developer.android.com/reference/android/graphics/Bitmap.html` from a byte array using `https://developer.android.com/reference/android/graphics/BitmapFactory.html` and the `https://developer.android.com/reference/kotlin/androidx/exifinterface/media/ExifInterface`. |
| `java-static https://developer.android.com/reference/android/graphics/Bitmap.html!` | `https://developer.android.com/reference/kotlin/androidx/media3/datasource/BitmapUtil#makeShared(android.graphics.Bitmap)(bitmap: https://developer.android.com/reference/android/graphics/Bitmap.html!)` Returns an immutable, sharable version of `https://developer.android.com/reference/android/graphics/Bitmap.html`. |

## Public functions

### decode

```
java-static fun decode(
    data: ByteArray<Byte>!,
    length: Int,
    options: BitmapFactory.Options?,
    maximumOutputDimension: Int
): Bitmap!
```

Decodes a `https://developer.android.com/reference/android/graphics/Bitmap.html` from a byte array using `https://developer.android.com/reference/android/graphics/BitmapFactory.html` and the `https://developer.android.com/reference/kotlin/androidx/exifinterface/media/ExifInterface`.

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte/index.html>!` | Byte array of compressed image data. |
| `length: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of bytes to parse. |
| `options: https://developer.android.com/reference/android/graphics/BitmapFactory.Options.html?` | The `https://developer.android.com/reference/android/graphics/BitmapFactory.Options.html` to decode the `data` with. |
| `maximumOutputDimension: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The largest output Bitmap dimension that can be returned by this method, or `https://developer.android.com/reference/kotlin/androidx/media3/common/C#LENGTH_UNSET()` if no limits are enforced. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/ParserException` | if the `data` could not be decoded. |
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### makeShared

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

Returns an immutable, sharable version of `https://developer.android.com/reference/android/graphics/Bitmap.html`. If the same instance of a shared bitmap is sent over binder calls, no additional copy is needed.

This method is a no-op if for API levels below 31 or if the Bitmap is already shared.

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

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