# SizeLimitedBitmapLoader

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

*** ** * ** ***

<br />

```
@UnstableApi
public final class SizeLimitedBitmapLoader implements BitmapLoader
```

<br />

*** ** * ** ***

A `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader` that limits the size of bitmaps loaded by `https://developer.android.com/reference/androidx/media3/session/SizeLimitedBitmapLoader#decodeBitmap(byte[])` or `https://developer.android.com/reference/androidx/media3/session/SizeLimitedBitmapLoader#loadBitmap(android.net.Uri)` request. Bitmaps with width or height larger than maxBitmapSize will be scaled down so that the larger dimension will be equal or less than maxBitmapSize.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/media3/session/SizeLimitedBitmapLoader#SizeLimitedBitmapLoader(androidx.media3.common.util.BitmapLoader,int,boolean)( https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader bitmapLoader, int maxBitmapSize, boolean makeShared )` Creates an instance that size limits the bitmap loaded by the `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader`. |

| ### Public methods |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/android/graphics/Bitmap.html>` | `https://developer.android.com/reference/androidx/media3/session/SizeLimitedBitmapLoader#decodeBitmap(byte[])(byte[] data)` Decodes an image from compressed binary data. |
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/android/graphics/Bitmap.html>` | `https://developer.android.com/reference/androidx/media3/session/SizeLimitedBitmapLoader#loadBitmap(android.net.Uri)(https://developer.android.com/reference/android/net/Uri.html uri)` Loads an image from `uri`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://guava.dev/releases/snapshot-android/api/docs/com/google/common/util/concurrent/ListenableFuture.html<https://developer.android.com/reference/android/graphics/Bitmap.html>` | `https://developer.android.com/reference/androidx/media3/session/SizeLimitedBitmapLoader#loadBitmapFromMetadata(androidx.media3.common.MediaMetadata)(https://developer.android.com/reference/androidx/media3/common/MediaMetadata metadata)` Loads an image from `https://developer.android.com/reference/androidx/media3/common/MediaMetadata`. |
| `boolean` | `https://developer.android.com/reference/androidx/media3/session/SizeLimitedBitmapLoader#supportsMimeType(java.lang.String)(https://developer.android.com/reference/java/lang/String.html mimeType)` Returns whether the given `mimeType` is supported. |

## Public constructors

### SizeLimitedBitmapLoader

```
public SizeLimitedBitmapLoader(
    BitmapLoader bitmapLoader,
    int maxBitmapSize,
    boolean makeShared
)
```

Creates an instance that size limits the bitmap loaded by the `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader bitmapLoader` | The `https://developer.android.com/reference/androidx/media3/common/util/BitmapLoader`. |
| `int maxBitmapSize` | The maximum size to limit the loaded `https://developer.android.com/reference/android/graphics/Bitmap.html` instances to. |
| `boolean makeShared` | Whether the `https://developer.android.com/reference/android/graphics/Bitmap.html` should be converted to an immutable, sharable instance that is most efficient for repeated transfer over binder interfaces. |

## Public methods

### decodeBitmap

```
public ListenableFuture<Bitmap> decodeBitmap(byte[] data)
```

Decodes an image from compressed binary data.

### loadBitmap

```
public ListenableFuture<Bitmap> loadBitmap(Uri uri)
```

Loads an image from `uri`.

### loadBitmapFromMetadata

```
public @Nullable ListenableFuture<Bitmap> loadBitmapFromMetadata(MediaMetadata metadata)
```

Loads an image from `https://developer.android.com/reference/androidx/media3/common/MediaMetadata`. Returns null if `metadata` doesn't contain bitmap information.

By default, the method will try to decode an image from `https://developer.android.com/reference/androidx/media3/common/MediaMetadata#artworkData()` if it is present. Otherwise, the method will try to load an image from `https://developer.android.com/reference/androidx/media3/common/MediaMetadata#artworkUri()` if it is present. The method will return null if neither `https://developer.android.com/reference/androidx/media3/common/MediaMetadata#artworkData()` nor `https://developer.android.com/reference/androidx/media3/common/MediaMetadata#artworkUri()` is present.

### supportsMimeType

```
public boolean supportsMimeType(String mimeType)
```

Returns whether the given `mimeType` is supported.