# DrawableKt

Added in 1.1.0

*** ** * ** ***


```
public final class DrawableKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/core/graphics/drawable/DrawableKt#(android.graphics.drawable.Drawable).toBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/drawable/Drawable.html receiver, @https://developer.android.com/reference/androidx/annotation/Px int width, @https://developer.android.com/reference/androidx/annotation/Px int height, https://developer.android.com/reference/android/graphics/Bitmap.Config.html config )` Return a `https://developer.android.com/reference/android/graphics/Bitmap.html` representation of this `https://developer.android.com/reference/android/graphics/drawable/Drawable.html`. |
| `static final https://developer.android.com/reference/android/graphics/Bitmap.html` | `https://developer.android.com/reference/androidx/core/graphics/drawable/DrawableKt#(android.graphics.drawable.Drawable).toBitmapOrNull(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/drawable/Drawable.html receiver, @https://developer.android.com/reference/androidx/annotation/Px int width, @https://developer.android.com/reference/androidx/annotation/Px int height, https://developer.android.com/reference/android/graphics/Bitmap.Config.html config )` 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. |
| `static final void` | `https://developer.android.com/reference/androidx/core/graphics/drawable/DrawableKt#(android.graphics.drawable.Drawable).updateBounds(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/drawable/Drawable.html receiver, @https://developer.android.com/reference/androidx/annotation/Px int left, @https://developer.android.com/reference/androidx/annotation/Px int top, @https://developer.android.com/reference/androidx/annotation/Px int right, @https://developer.android.com/reference/androidx/annotation/Px int bottom )` Updates this drawable's bounds. |

## Public methods

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

```
public static final @NonNull Bitmap toBitmap(
    @NonNull Drawable receiver,
    @Px int width,
    @Px int height,
    Bitmap.Config config
)
```

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/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)`, `https://developer.android.com/reference/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Px int width` | Width of the desired bitmap. Defaults to `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicWidth()`. |
| `@https://developer.android.com/reference/androidx/annotation/Px int height` | Height of the desired bitmap. Defaults to `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicHeight()`. |
| `https://developer.android.com/reference/android/graphics/Bitmap.Config.html config` | 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/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmapOrNull(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)` |   |

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

```
public static final Bitmap toBitmapOrNull(
    @NonNull Drawable receiver,
    @Px int width,
    @Px int height,
    Bitmap.Config config
)
```

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/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmapOrNull(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)`, `https://developer.android.com/reference/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Px int width` | Width of the desired bitmap. Defaults to `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicWidth()`. |
| `@https://developer.android.com/reference/androidx/annotation/Px int height` | Height of the desired bitmap. Defaults to `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicHeight()`. |
| `https://developer.android.com/reference/android/graphics/Bitmap.Config.html config` | 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/androidx/core/graphics/drawable/package-summary#(android.graphics.drawable.Drawable).toBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)` |   |

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

```
public static final void updateBounds(
    @NonNull Drawable receiver,
    @Px int left,
    @Px int top,
    @Px int right,
    @Px int bottom
)
```

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