# Brush

Artifact: [androidx.ink:ink-brush](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/brush/Brush.kt+class:androidx.ink.brush.Brush) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

*** ** * ** ***


```
public final class Brush
```

<br />

*** ** * ** ***

Defines how stroke inputs are interpreted to create the visual representation of a stroke.

The type completely describes how inputs are used to create stroke meshes, and how those meshes should be drawn by stroke renderers. In an analogous way to "font" and "font family", a `https://developer.android.com/reference/androidx/ink/brush/Brush` can be considered an instance of a `https://developer.android.com/reference/androidx/ink/brush/BrushFamily` with a particular color, `https://developer.android.com/reference/androidx/ink/brush/Brush#size()`, and an extra parameter controlling visual fidelity, called `https://developer.android.com/reference/androidx/ink/brush/Brush#epsilon()`.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/ink/brush/Brush.Builder` Builder for `https://developer.android.com/reference/androidx/ink/brush/Brush`. |
| `public static class https://developer.android.com/reference/androidx/ink/brush/Brush.Companion` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/ink/brush/Brush#Brush(androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/BrushFamily family, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon )` The default color of a `https://developer.android.com/reference/androidx/ink/brush/Brush` is pure black. |

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush.Builder` | `https://developer.android.com/reference/androidx/ink/brush/Brush#builder()()` Returns a new `https://developer.android.com/reference/androidx/ink/brush/Brush.Builder`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush` | `https://developer.android.com/reference/androidx/ink/brush/Brush#copy(androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/BrushFamily family, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon )` Creates a copy of `this` and allows named properties to be altered while keeping the rest unchanged. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush` | `https://developer.android.com/reference/androidx/ink/brush/Brush#copyWithColorIntArgb(kotlin.Int,androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/ColorInt int colorIntArgb, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/BrushFamily family, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon )` Creates a copy of `this` and allows named properties to be altered while keeping the rest unchanged. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush` | `https://developer.android.com/reference/androidx/ink/brush/Brush#copyWithColorLong(kotlin.Long,androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/ColorLong long colorLong, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/BrushFamily family, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size, @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon )` Creates a copy of `this` and allows named properties to be altered while keeping the rest unchanged. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush` | `https://developer.android.com/reference/androidx/ink/brush/Brush#createWithColorIntArgb(androidx.ink.brush.BrushFamily,kotlin.Int,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/BrushFamily family, @https://developer.android.com/reference/androidx/annotation/ColorInt int colorIntArgb, float size, float epsilon )` Returns a new `https://developer.android.com/reference/androidx/ink/brush/Brush` with the color specified by a `https://developer.android.com/reference/androidx/annotation/ColorInt`, which is in the sRGB color space by definition. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush` | `https://developer.android.com/reference/androidx/ink/brush/Brush#createWithColorLong(androidx.ink.brush.BrushFamily,kotlin.Long,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/BrushFamily family, @https://developer.android.com/reference/androidx/annotation/ColorLong long colorLong, float size, float epsilon )` Returns a new `https://developer.android.com/reference/androidx/ink/brush/Brush` with the color specified by a `https://developer.android.com/reference/androidx/annotation/ColorLong`, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3. |
| `boolean` | `https://developer.android.com/reference/androidx/ink/brush/Brush#equals(kotlin.Any)(https://developer.android.com/reference/java/lang/Object.html other)` |
| `final @https://developer.android.com/reference/androidx/annotation/ColorInt int` | `https://developer.android.com/reference/androidx/ink/brush/Brush#getColorIntArgb()()` The brush color as a `https://developer.android.com/reference/androidx/annotation/ColorInt`, which can only express colors in the sRGB color space. |
| `final @https://developer.android.com/reference/androidx/annotation/ColorLong long` | `https://developer.android.com/reference/androidx/ink/brush/Brush#getColorLong()()` The brush color as a `https://developer.android.com/reference/androidx/annotation/ColorLong`, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3. |
| `final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float` | `https://developer.android.com/reference/androidx/ink/brush/Brush#getEpsilon()()` The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/BrushFamily` | `https://developer.android.com/reference/androidx/ink/brush/Brush#getFamily()()` |
| `final @https://developer.android.com/reference/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float` | `https://developer.android.com/reference/androidx/ink/brush/Brush#getSize()()` The overall thickness of strokes created with a given brush, in the same units as the stroke coordinate system. |
| `int` | `https://developer.android.com/reference/androidx/ink/brush/Brush#hashCode()()` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush.Builder` | `https://developer.android.com/reference/androidx/ink/brush/Brush#toBuilder()()` Returns a `https://developer.android.com/reference/androidx/ink/brush/Brush.Builder` with values set equivalent to `this`. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/ink/brush/Brush#toString()()` |

| ### Extension functions |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/ink/brush/BrushUtil.https://developer.android.com/reference/androidx/ink/brush/Brush#(androidx.ink.brush.Brush).copyWithAndroidColor(android.graphics.Color,androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Color.html color, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/BrushFamily family, float size, float epsilon )` Creates a copy of `this` `https://developer.android.com/reference/androidx/ink/brush/Brush` and allows named properties to be altered while keeping the rest unchanged. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/graphics/Color.html` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/ink/brush/BrushUtil.https://developer.android.com/reference/androidx/ink/brush/Brush#(androidx.ink.brush.Brush).createAndroidColor()(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/ink/brush/Brush receiver)` The brush color as an `https://developer.android.com/reference/android/graphics/Color.html` instance, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3. |

## Public constructors

### Brush

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public Brush(
    @NonNull BrushFamily family,
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size,
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon
)
```

The default color of a `https://developer.android.com/reference/androidx/ink/brush/Brush` is pure black. To set a custom color, use `https://developer.android.com/reference/androidx/ink/brush/Brush#createWithColorLong(androidx.ink.brush.BrushFamily,kotlin.Long,kotlin.Float,kotlin.Float)` or `https://developer.android.com/reference/androidx/ink/brush/Brush#createWithColorIntArgb(androidx.ink.brush.BrushFamily,kotlin.Int,kotlin.Float,kotlin.Float)`.

## Public methods

### builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public static final @NonNull Brush.Builder builder()
```

Returns a new `https://developer.android.com/reference/androidx/ink/brush/Brush.Builder`.

### copy

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull Brush copy(
    @NonNull BrushFamily family,
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size,
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon
)
```

Creates a copy of `this` and allows named properties to be altered while keeping the rest unchanged. To change the color, use `https://developer.android.com/reference/androidx/ink/brush/Brush#copyWithColorLong(kotlin.Long,androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float)` or `https://developer.android.com/reference/androidx/ink/brush/Brush#copyWithColorIntArgb(kotlin.Int,androidx.ink.brush.BrushFamily,kotlin.Float,kotlin.Float)`.

### copyWithColorIntArgb

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull Brush copyWithColorIntArgb(
    @ColorInt int colorIntArgb,
    @NonNull BrushFamily family,
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size,
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon
)
```

Creates a copy of `this` and allows named properties to be altered while keeping the rest unchanged. The color is specified as a `https://developer.android.com/reference/androidx/annotation/ColorInt`, which is in the sRGB color space by definition. Note that the `https://developer.android.com/reference/androidx/annotation/ColorInt` channel order puts alpha first (in the most significant byte).

Kotlin interprets integer literals greater than `0x7fffffff` as `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html`s, so callers that want to specify a literal `https://developer.android.com/reference/androidx/annotation/ColorInt` with alpha \>= 0x80 must call `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/to-int.html` on the literal.

### copyWithColorLong

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull Brush copyWithColorLong(
    @ColorLong long colorLong,
    @NonNull BrushFamily family,
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float size,
    @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float epsilon
)
```

Creates a copy of `this` and allows named properties to be altered while keeping the rest unchanged. The color is specified as a `https://developer.android.com/reference/androidx/annotation/ColorLong`, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Some libraries (notably Jetpack UI Graphics) use `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-u-long/index.html` for `https://developer.android.com/reference/androidx/annotation/ColorLong`s, so the caller must call `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-u-long/to-long.html` on such a value before passing it to this method.

### createWithColorIntArgb

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public static final @NonNull Brush createWithColorIntArgb(
    @NonNull BrushFamily family,
    @ColorInt int colorIntArgb,
    float size,
    float epsilon
)
```

Returns a new `https://developer.android.com/reference/androidx/ink/brush/Brush` with the color specified by a `https://developer.android.com/reference/androidx/annotation/ColorInt`, which is in the sRGB color space by definition. Note that the `https://developer.android.com/reference/androidx/annotation/ColorInt` channel order puts alpha first (in the most significant byte).

Kotlin interprets integer literals greater than `0x7fffffff` as `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html`s, so callers that want to specify a literal `https://developer.android.com/reference/androidx/annotation/ColorInt` with alpha \>= 0x80 must call `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/to-int.html` on the literal.

### createWithColorLong

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public static final @NonNull Brush createWithColorLong(
    @NonNull BrushFamily family,
    @ColorLong long colorLong,
    float size,
    float epsilon
)
```

Returns a new `https://developer.android.com/reference/androidx/ink/brush/Brush` with the color specified by a `https://developer.android.com/reference/androidx/annotation/ColorLong`, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Some libraries (notably Jetpack UI Graphics) use `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-u-long/index.html` for `https://developer.android.com/reference/androidx/annotation/ColorLong`s, so the caller must call `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-u-long/to-long.html` on such a value before passing it to this method.

### equals

```
public boolean equals(Object other)
```

### getColorIntArgb

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @ColorInt int getColorIntArgb()
```

The brush color as a `https://developer.android.com/reference/androidx/annotation/ColorInt`, which can only express colors in the sRGB color space. For clients that want to support wide-gamut colors, use `https://developer.android.com/reference/androidx/ink/brush/Brush#colorLong()`.

### getColorLong

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @ColorLong long getColorLong()
```

The brush color as a `https://developer.android.com/reference/androidx/annotation/ColorLong`, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

### getEpsilon

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float getEpsilon()
```

The smallest distance for which two points should be considered visually distinct for stroke generation geometry purposes. Effectively, it is the visual fidelity of strokes created with this brush, where any (lack of) visual fidelity can be observed by a user the further zoomed in they are on the stroke. Lower values of `https://developer.android.com/reference/androidx/ink/brush/Brush#epsilon()` result in higher fidelity strokes at the cost of somewhat higher memory usage. This value, like `https://developer.android.com/reference/androidx/ink/brush/Brush#size()`, is in the same units as the stroke coordinate system. A size of 0.1 physical pixels at the default zoom level is a good starting point that can tolerate a reasonable amount of zooming in with high quality visual results.

### getFamily

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull BrushFamily getFamily()
```

### getSize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @FloatRange(from = 0.0, fromInclusive = false, to = Infinity, toInclusive = false) float getSize()
```

The overall thickness of strokes created with a given brush, in the same units as the stroke coordinate system. This must be at least as big as `https://developer.android.com/reference/androidx/ink/brush/Brush#epsilon()`.

### hashCode

```
public int hashCode()
```

### toBuilder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/ink#1.0.0)

```
public final @NonNull Brush.Builder toBuilder()
```

Returns a `https://developer.android.com/reference/androidx/ink/brush/Brush.Builder` with values set equivalent to `this`. Java developers, use the returned builder to build a copy of a Brush. Kotlin developers, see `https://developer.android.com/reference/androidx/ink/brush/Brush#copy(androidx.ink.brush.BrushFamily,androidx.ink.brush.color.Color,kotlin.Float,kotlin.Float)` method.

### toString

```
public @NonNull String toString()
```

## Extension functions

### BrushUtil.copyWithAndroidColor

Artifact: [androidx.ink:ink-brush](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/brush/BrushExtensions.android.kt+function:copyWithAndroidColor)

```
@RequiresApi(value = 26)
public final @NonNull Brush BrushUtil.copyWithAndroidColor(
    @NonNull Brush receiver,
    @NonNull Color color,
    @NonNull BrushFamily family,
    float size,
    float epsilon
)
```

Creates a copy of `this` `https://developer.android.com/reference/androidx/ink/brush/Brush` and allows named properties to be altered while keeping the rest unchanged. The color is specified as an `https://developer.android.com/reference/android/graphics/Color.html` instance, which can encode several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

### BrushUtil.createAndroidColor

Artifact: [androidx.ink:ink-brush](https://developer.android.com/jetpack/androidx/releases/ink) [View Source](https://cs.android.com/search?q=file:androidx/ink/brush/BrushExtensions.android.kt+function:createAndroidColor)

```
@RequiresApi(value = 26)
public final @NonNull Color BrushUtil.createAndroidColor(@NonNull Brush receiver)
```

The brush color as an `https://developer.android.com/reference/android/graphics/Color.html` instance, which can express colors in several different color spaces. sRGB and Display P3 are supported; a color in any other color space will be converted to Display P3.

Unless an instance of `https://developer.android.com/reference/android/graphics/Color.html` is actually needed, prefer to use `https://developer.android.com/reference/androidx/ink/brush/Brush#colorLong()` to get the color without causing an allocation, especially in performance-sensitive code. `https://developer.android.com/reference/androidx/ink/brush/Brush#colorLong()` is fully compatible with the `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` representation of `https://developer.android.com/reference/android/graphics/Color.html`.