# androidx.core.graphics.drawable

*** ** * ** ***

## Classes

|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/DrawableCompat` | Helper for accessing features in `https://developer.android.com/reference/android/graphics/drawable/Drawable.html`. |
| `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/IconCompat` | Helper for accessing features in `https://developer.android.com/reference/android/graphics/drawable/Icon.html`. |
| `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/RoundedBitmapDrawable` | A Drawable that wraps a bitmap and can be drawn with rounded corners. |
| `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/RoundedBitmapDrawableFactory` | Constructs `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/RoundedBitmapDrawable` objects, either from Bitmaps directly, or from streams and files. |

## Extension functions summary

|---|---|
| `inline https://developer.android.com/reference/android/graphics/drawable/Icon.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/android/graphics/Bitmap.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.Bitmap).toAdaptiveIcon()()` Create an `https://developer.android.com/reference/android/graphics/drawable/Icon.html` from this adaptive `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)(width: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, config: https://developer.android.com/reference/android/graphics/Bitmap.Config.html?)` Return a `https://developer.android.com/reference/android/graphics/Bitmap.html` representation of this `https://developer.android.com/reference/android/graphics/drawable/Drawable.html`. |
| `https://developer.android.com/reference/android/graphics/Bitmap.html?` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmapOrNull(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)( width: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, config: https://developer.android.com/reference/android/graphics/Bitmap.Config.html? )` Returns a `https://developer.android.com/reference/android/graphics/Bitmap.html` representation of this `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` or `null` if the drawable cannot be represented as a bitmap. |
| `inline https://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/ColorInt https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(kotlin.Int).toDrawable()()` Create a `https://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html` from this color value. |
| `inline https://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/android/graphics/Color.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.Color).toDrawable()()` Create a `https://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html` from this `https://developer.android.com/reference/android/graphics/Color.html` (via `https://developer.android.com/reference/android/graphics/Color.html#toArgb()`). |
| `inline https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html` | `https://developer.android.com/reference/android/graphics/Bitmap.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.Bitmap).toDrawable(android.content.res.Resources)(resources: https://developer.android.com/reference/android/content/res/Resources.html)` Create a `https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html` from this `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `inline https://developer.android.com/reference/android/graphics/drawable/Icon.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/android/graphics/Bitmap.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.Bitmap).toIcon()()` Create an `https://developer.android.com/reference/android/graphics/drawable/Icon.html` from this `https://developer.android.com/reference/android/graphics/Bitmap.html`. |
| `inline https://developer.android.com/reference/android/graphics/drawable/Icon.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/android/net/Uri.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.net.Uri).toIcon()()` Create an `https://developer.android.com/reference/android/graphics/drawable/Icon.html` from this `https://developer.android.com/reference/android/net/Uri.html`. |
| `inline https://developer.android.com/reference/android/graphics/drawable/Icon.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/RequiresApi(value = 26) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(kotlin.ByteArray).toIcon()()` Create an `https://developer.android.com/reference/android/graphics/drawable/Icon.html` from this `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html.https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).updateBounds(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)(left: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, top: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, right: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bottom: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Updates this drawable's bounds. |

## Extension functions

### Bitmap.toAdaptiveIcon

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/Icon.kt+function:toAdaptiveIcon) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
@RequiresApi(value = 26)
inline fun Bitmap.toAdaptiveIcon(): Icon
```

Create an `https://developer.android.com/reference/android/graphics/drawable/Icon.html` from this adaptive `https://developer.android.com/reference/android/graphics/Bitmap.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Icon.html#createWithAdaptiveBitmap(android.graphics.Bitmap)` |   |

### Drawable.toBitmap

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/Drawable.kt+function:toBitmap) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
fun Drawable.toBitmap(
    width: @Px Int = intrinsicWidth,
    height: @Px Int = intrinsicHeight,
    config: Bitmap.Config? = null
): Bitmap
```

Return a `https://developer.android.com/reference/android/graphics/Bitmap.html` representation of this `https://developer.android.com/reference/android/graphics/drawable/Drawable.html`.

If this instance is a `https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html` and the `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)`, `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)`, and `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)` match, the underlying `https://developer.android.com/reference/android/graphics/Bitmap.html` instance will be returned directly. If any of those three properties differ then a new `https://developer.android.com/reference/android/graphics/Bitmap.html` is created. For all other `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` types, a new `https://developer.android.com/reference/android/graphics/Bitmap.html` is created.

| Parameters |
|---|---|
| `width: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = intrinsicWidth` | Width of the desired bitmap. Defaults to `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicWidth()`. |
| `height: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = intrinsicHeight` | Height of the desired bitmap. Defaults to `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicHeight()`. |
| `config: https://developer.android.com/reference/android/graphics/Bitmap.Config.html? = null` | Bitmap config of the desired bitmap. Null attempts to use the native config, if any. Defaults to `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` otherwise. |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the underlying drawable is a `https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html` where `https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html#getBitmap()` returns `null` or the drawable cannot otherwise be represented as a bitmap |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmapOrNull(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)` |   |

### Drawable.toBitmapOrNull

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/Drawable.kt+function:toBitmapOrNull) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/core#1.8.0)

```
fun Drawable.toBitmapOrNull(
    width: @Px Int = intrinsicWidth,
    height: @Px Int = intrinsicHeight,
    config: Bitmap.Config? = null
): Bitmap?
```

Returns a `https://developer.android.com/reference/android/graphics/Bitmap.html` representation of this `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` or `null` if the drawable cannot be represented as a bitmap.

If this instance is a `https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html` and the `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmapOrNull(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)`, `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmapOrNull(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)`, and `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmapOrNull(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)` match, the underlying `https://developer.android.com/reference/android/graphics/Bitmap.html` instance will be returned directly. If any of those three properties differ then a new `https://developer.android.com/reference/android/graphics/Bitmap.html` is created. For all other `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` types, a new `https://developer.android.com/reference/android/graphics/Bitmap.html` is created.

If the result of `https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html#getBitmap()` is `null` or the drawable cannot otherwise be represented as a bitmap, returns `null`.

| Parameters |
|---|---|
| `width: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = intrinsicWidth` | Width of the desired bitmap. Defaults to `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicWidth()`. |
| `height: @https://developer.android.com/reference/kotlin/androidx/annotation/Px https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = intrinsicHeight` | Height of the desired bitmap. Defaults to `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicHeight()`. |
| `config: https://developer.android.com/reference/android/graphics/Bitmap.Config.html? = null` | Bitmap config of the desired bitmap. Null attempts to use the native config, if any. Defaults to `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888` otherwise. |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)` |   |

### Int.toDrawable

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/ColorDrawable.kt+function:toDrawable) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
inline fun @ColorInt Int.toDrawable(): ColorDrawable
```

Create a `https://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html` from this color value.

### Color.toDrawable

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/ColorDrawable.kt+function:toDrawable) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
@RequiresApi(value = 26)
inline fun Color.toDrawable(): ColorDrawable
```

Create a `https://developer.android.com/reference/android/graphics/drawable/ColorDrawable.html` from this `https://developer.android.com/reference/android/graphics/Color.html` (via `https://developer.android.com/reference/android/graphics/Color.html#toArgb()`).

### Bitmap.toDrawable

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/BitmapDrawable.kt+function:toDrawable) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
inline fun Bitmap.toDrawable(resources: Resources): BitmapDrawable
```

Create a `https://developer.android.com/reference/android/graphics/drawable/BitmapDrawable.html` from this `https://developer.android.com/reference/android/graphics/Bitmap.html`.

### Bitmap.toIcon

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/Icon.kt+function:toIcon) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
@RequiresApi(value = 26)
inline fun Bitmap.toIcon(): Icon
```

Create an `https://developer.android.com/reference/android/graphics/drawable/Icon.html` from this `https://developer.android.com/reference/android/graphics/Bitmap.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Icon.html#createWithBitmap(android.graphics.Bitmap)` |   |

### Uri.toIcon

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/Icon.kt+function:toIcon) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
@RequiresApi(value = 26)
inline fun Uri.toIcon(): Icon
```

Create an `https://developer.android.com/reference/android/graphics/drawable/Icon.html` from this `https://developer.android.com/reference/android/net/Uri.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Icon.html#createWithContentUri(android.net.Uri)` |   |

### ByteArray.toIcon

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/Icon.kt+function:toIcon) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
@RequiresApi(value = 26)
inline fun ByteArray.toIcon(): Icon
```

Create an `https://developer.android.com/reference/android/graphics/drawable/Icon.html` from this `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-byte-array/index.html`.

| See also |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Icon.html#createWithData(byte[], int, int)` |   |

### Drawable.updateBounds

Artifact: [androidx.core:core](https://developer.android.com/jetpack/androidx/releases/core) [View Source](https://cs.android.com/search?q=file:androidx/core/graphics/drawable/Drawable.kt+function:updateBounds) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/core#1.1.0)

```
fun Drawable.updateBounds(
    left: @Px Int = bounds.left,
    top: @Px Int = bounds.top,
    right: @Px Int = bounds.right,
    bottom: @Px Int = bounds.bottom
): Unit
```

Updates this drawable's bounds. This version of the method allows using named parameters to just set one or more axes.

| See also |
|---|---|
| `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setBounds(android.graphics.Rect)` |   |