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

*** ** * ** ***


```
@UnstableApi
public final class BitmapUtil
```

<br />

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/datasource/BitmapUtil#decode(byte[],int,android.graphics.BitmapFactory.Options,int)( byte[] data, int length, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/graphics/BitmapFactory.Options.html options, int maximumOutputDimension )` 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/androidx/exifinterface/media/ExifInterface`. |
| `static https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/media3/datasource/BitmapUtil#makeShared(android.graphics.Bitmap)(https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` Returns an immutable, sharable version of `https://developer.android.com/reference/android/graphics/Bitmap.html`. |

## Public methods

### decode

```
public static Bitmap decode(
    byte[] data,
    int length,
    @Nullable BitmapFactory.Options options,
    int maximumOutputDimension
)
```

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/androidx/exifinterface/media/ExifInterface`.

| Parameters |
|---|---|
| `byte[] data` | Byte array of compressed image data. |
| `int length` | The number of bytes to parse. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/graphics/BitmapFactory.Options.html options` | The `https://developer.android.com/reference/android/graphics/BitmapFactory.Options.html` to decode the `data` with. |
| `int maximumOutputDimension` | The largest output Bitmap dimension that can be returned by this method, or `https://developer.android.com/reference/androidx/media3/common/C#LENGTH_UNSET()` if no limits are enforced. |

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

### makeShared

```
public static Bitmap makeShared(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 |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html bitmap` | 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`. |