# BitmapKt

Added in 1.1.0

*** ** * ** ***


```
public final class BitmapKt
```

<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/BitmapKt#(android.graphics.Bitmap).applyCanvas(kotlin.Function1)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Canvas.html, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> block )` Creates a new `https://developer.android.com/reference/android/graphics/Canvas.html` to draw on this bitmap and executes the specified `https://developer.android.com/reference/androidx/core/graphics/package-summary#(android.graphics.Bitmap).applyCanvas(kotlin.Function1)` on the newly created canvas. |
| `static final boolean` | `https://developer.android.com/reference/androidx/core/graphics/BitmapKt#(android.graphics.Bitmap).contains(android.graphics.Point)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Point.html p)` Returns true if the specified point is inside the bitmap. |
| `static final boolean` | `https://developer.android.com/reference/androidx/core/graphics/BitmapKt#(android.graphics.Bitmap).contains(android.graphics.PointF)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/PointF.html p)` Returns true if the specified point is inside the bitmap. |
| `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/BitmapKt#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)(int width, int height, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.Config.html config)` Returns a mutable bitmap with the specified `https://developer.android.com/reference/androidx/core/graphics/package-summary#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)` and `https://developer.android.com/reference/androidx/core/graphics/package-summary#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)`. |
| `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/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/core/graphics/BitmapKt#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config,kotlin.Boolean,android.graphics.ColorSpace)( int width, int height, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.Config.html config, boolean hasAlpha, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/ColorSpace.html colorSpace )` Returns a mutable bitmap with the specified `https://developer.android.com/reference/androidx/core/graphics/package-summary#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config,kotlin.Boolean,android.graphics.ColorSpace)` and `https://developer.android.com/reference/androidx/core/graphics/package-summary#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config,kotlin.Boolean,android.graphics.ColorSpace)`. |
| `static final int` | `https://developer.android.com/reference/androidx/core/graphics/BitmapKt#(android.graphics.Bitmap).get(kotlin.Int,kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html receiver, int x, int y)` Returns the value of the pixel at the specified location. |
| `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/BitmapKt#(android.graphics.Bitmap).scale(kotlin.Int,kotlin.Int,kotlin.Boolean)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html receiver, int width, int height, boolean filter)` Creates a new bitmap, scaled from this bitmap, when possible. |
| `static final void` | `https://developer.android.com/reference/androidx/core/graphics/BitmapKt#(android.graphics.Bitmap).set(kotlin.Int,kotlin.Int,kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html receiver, int x, int y, @https://developer.android.com/reference/androidx/annotation/ColorInt int color)` Writes the specified `https://developer.android.com/reference/android/graphics/Color.html` into the bitmap (assuming it is mutable) at the specified `(x, y)` coordinate. |

## Public methods

### applyCanvas

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

```
public static final @NonNull Bitmap applyCanvas(
    @NonNull Bitmap receiver,
    @NonNull Function1<@NonNull Canvas, Unit> block
)
```

Creates a new `https://developer.android.com/reference/android/graphics/Canvas.html` to draw on this bitmap and executes the specified `https://developer.android.com/reference/androidx/core/graphics/package-summary#(android.graphics.Bitmap).applyCanvas(kotlin.Function1)` on the newly created canvas. Example:

```
return Bitmap.createBitmap(…).applyCanvas {
   drawLine(…)
   translate(…)
   drawRect(…)
}
```

### contains

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

```
public static final boolean contains(@NonNull Bitmap receiver, @NonNull Point p)
```

Returns true if the specified point is inside the bitmap. A point is contained if: 0 \<= x \< width and 0 \<= y \< height. An empty bitmap never contains any point.

### contains

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

```
public static final boolean contains(@NonNull Bitmap receiver, @NonNull PointF p)
```

Returns true if the specified point is inside the bitmap. A point is contained if: 0 \<= x \< width and 0 \<= y \< height. An empty bitmap never contains any point.

### createBitmap

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

```
public static final @NonNull Bitmap createBitmap(int width, int height, @NonNull Bitmap.Config config)
```

Returns a mutable bitmap with the specified `https://developer.android.com/reference/androidx/core/graphics/package-summary#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)` and `https://developer.android.com/reference/androidx/core/graphics/package-summary#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config)`. A config can be optionally specified. If not, the default config is `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888`.

| Parameters |
|---|---|
| `int width` | The new bitmap's desired width |
| `int height` | The new bitmap's desired height |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.Config.html config` | The new bitmap's desired `https://developer.android.com/reference/android/graphics/Bitmap.Config.html` |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html` | A new bitmap with the specified dimensions and config |

### createBitmap

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

```
@RequiresApi(value = 26)
public static final @NonNull Bitmap createBitmap(
    int width,
    int height,
    @NonNull Bitmap.Config config,
    boolean hasAlpha,
    @NonNull ColorSpace colorSpace
)
```

Returns a mutable bitmap with the specified `https://developer.android.com/reference/androidx/core/graphics/package-summary#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config,kotlin.Boolean,android.graphics.ColorSpace)` and `https://developer.android.com/reference/androidx/core/graphics/package-summary#createBitmap(kotlin.Int,kotlin.Int,android.graphics.Bitmap.Config,kotlin.Boolean,android.graphics.ColorSpace)`. The config, transparency and color space can optionally be specified. They respectively default to `https://developer.android.com/reference/android/graphics/Bitmap.Config.html#ARGB_8888`, `true` and `https://developer.android.com/reference/android/graphics/ColorSpace.Named.html#SRGB`.

| Parameters |
|---|---|
| `int width` | The new bitmap's desired width |
| `int height` | The new bitmap's desired height |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.Config.html config` | The new bitmap's desired `https://developer.android.com/reference/android/graphics/Bitmap.Config.html` |
| `boolean hasAlpha` | Whether the new bitmap is opaque or not |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/ColorSpace.html colorSpace` | The new bitmap's color space |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html` | A new bitmap with the specified dimensions and config |

### get

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

```
public static final int get(@NonNull Bitmap receiver, int x, int y)
```

Returns the value of the pixel at the specified location. The returned value is a `https://developer.android.com/reference/android/graphics/Color.html` in the sRGB color space.

### scale

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

```
public static final @NonNull Bitmap scale(@NonNull Bitmap receiver, int width, int height, boolean filter)
```

Creates a new bitmap, scaled from this bitmap, when possible. If the specified `https://developer.android.com/reference/androidx/core/graphics/package-summary#(android.graphics.Bitmap).scale(kotlin.Int,kotlin.Int,kotlin.Boolean)` and `https://developer.android.com/reference/androidx/core/graphics/package-summary#(android.graphics.Bitmap).scale(kotlin.Int,kotlin.Int,kotlin.Boolean)` are the same as the current width and height of this bitmap, this bitmap is returned and no new bitmap is created.

| Parameters |
|---|---|
| `int width` | The new bitmap's desired width |
| `int height` | The new bitmap's desired height |
| `boolean filter` | `true` if the source should be filtered (`true` by default) |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Bitmap.html` | The new scaled bitmap or the source bitmap if no scaling is required. |

### set

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

```
public static final void set(@NonNull Bitmap receiver, int x, int y, @ColorInt int color)
```

Writes the specified `https://developer.android.com/reference/android/graphics/Color.html` into the bitmap (assuming it is mutable) at the specified `(x, y)` coordinate. The specified color is converted from sRGB to the bitmap's color space if needed.