Ink Custom Brush Builder
Android (Google)OfficialCreated by Google LLCDistributed by Android (Google)
- Skill
- Tool integration
- Software development
- Apache-2.0
- No issues found
AutoGineer summary
Written by AutoGineer from the skill’s own files, not by the author
The ink-custom-brush-builder skill provides a structured approach to creating programmatic custom brushes for Android applications utilizing the Jetpack Ink library (version 1.1.0-alpha03 and higher). It enables developers to define complex brush behaviors, multi-coat layers, and custom textures using Kotlin constructors rather than manual protocol buffer builders. The skill covers the entire brush hierarchy, including BrushFamily, BrushCoat, BrushTip, BrushPaint, and BrushBehavior node graphs, ensuring developers can implement responsive, high-fidelity drawing tools with features like pressure, tilt, and speed sensitivity.
What it does
- Generates complete Kotlin implementations for BrushFamily, BrushCoat, BrushTip, BrushPaint, and BrushBehavior.
- Configures dynamic stylus and touch responses using BrushBehavior node graphs.
- Applies tiling or particle stamping textures to brushes.
- Sets up input smoothing via SlidingWindowModel.
- Provides guidance on encoding and decoding custom BrushFamily definitions.
- Ensures correct dependency versions for Jetpack Ink libraries.
When to use it
- When you need to create custom brush styles beyond the provided stock brushes.
- When implementing brushes that respond dynamically to stylus pressure, tilt, or speed.
- When building multi-coat layered brushes with specific texture or color functions.
- When you need to serialize and deserialize custom brush definitions.
- When configuring specific input smoothing for drawing strokes.
Advantages
- Uses public Kotlin constructors for type-safe brush definition.
- Enables complex, organic stroke behaviors through procedural noise and response nodes.
- Supports advanced texture mapping without manual bitmap shader implementation.
- Provides a consistent, documented workflow for brush structure and behavior.
- Avoids common antipatterns like manual Bézier smoothing or raw proto builders.
Usage examples
- “How do I create a custom pressure-sensitive pen brush?”
- The agent will provide a Kotlin code snippet using BrushFamily, BrushCoat, and a BrushBehavior node graph that maps NORMALIZED_PRESSURE to SIZE_MULTIPLIER.
- “Help me add a grain texture to my custom brush.”
- The agent will guide you through implementing a BrushPaint.TilingTexture, identifying the necessary drawable resource, and registering it in the TextureBitmapStore.
Install
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/android/ink-custom-brush-builder/downloadUnzip it into the cross-client skills folder of your project:
mkdir -p .agents/skills && unzip ink-custom-brush-builder.zip -d .agents/skills
Documentation by Google LLC
Custom brushes in the Android Ink API are built around the BrushFamily
hierarchy:
BrushFamily
├── InputModel (BrushFamily.InputModel.SlidingWindowModel or PASSTHROUGH_MODEL)
└── BrushCoat[] (one or more rendering layers)
├── BrushTip (shape: scaleX, scaleY, cornerRounding, rotationDegrees, slantDegrees, pinch)
│ └── BrushBehavior[] (dynamic response to stylus or touch input)
│ └── Tree: TargetNode(input = [Operators](input = SourceNode))
└── BrushPaint (visual appearance)
├── SelfOverlap (ANY, ACCUMULATE, or DISCARD)
├── TextureLayer[] (BrushPaint.TilingTexture or BrushPaint.StampingTexture)
└── BrushPaint.ColorFunction[] (OpacityMultiplier or ReplaceColor)Create a Brush by combining a custom BrushFamily with a Compose Color,
size, and epsilon:
val brush = Brush.createWithComposeColor(
family = myCustomFamily,
color = Color.Black,
size = 10f,
epsilon = 0.1f,
)<br />
Version and experimental API requirements :
Requires
androidx.ink1.1.0-alpha03and higher : In1.0.0(Stable) and1.1.0-alpha01-alpha02,BrushFamily(...),BrushCoat,BrushTip,BrushPaint,BrushBehavior, andandroidx.ink.brush.behavior.*nodes were@RestrictTo(LIBRARY_GROUP)(in1.0.0stable, custom brushes can only be loaded from binary proto streams usingBrushFamily.decode). Starting in1.1.0-alpha03and higher , programmatic custom brush constructors graduated to public API (BrushPaint.TilingTexture,BrushPaint.StampingTexture,BrushPaint.ColorFunction,BrushFamily.InputModel.SlidingWindowModel, and all behavior nodes).No
@OptInrequired in1.1.0-alpha03and higher : All public custom brush classes andink-storageBrushFamilyserialization APIs (BrushFamily.encodeanddecode,AndroidBrushFamilySerialization,BrushFamilyDecodeCallback) are unannotated in1.1.0-alpha03and higher (ExperimentalInkCustomBrushApiis@RestrictTo(LIBRARY_GROUP)in1.1.0-alpha05and higher, and is only required onBrushFamilyserialization in1.0.0stable).
Workflow and task routing
Follow these conditional instructions based on the requested custom brush task:
Step 1 (Dependencies) : When setting up an Android project for programmatic custom brushes, ask user permission before editing build files and verify that
androidx.ink:ink-brush,androidx.ink:ink-brush-compose,androidx.ink:ink-storage, andandroidx.ink:ink-nativeloaderuse version1.1.0-alpha03or higher ingradle/libs.versions.tomlandapp/build.gradle.kts.Step 2 (Hierarchy, tip shape, paint, and input smoothing) : When defining
BrushFamilyand multi-coatBrushCoatlayers, configuringBrushTipgeometry (scaleX,scaleY,cornerRounding,rotationDegrees,slantDegrees,pinch), settingBrushPaintproperties (SelfOverlap,ColorFunction), or smoothing stroke input withBrushFamily.InputModel.SlidingWindowModel, you MUST follow brush-structure.md. For baselineBrushcreation or1.0.0resource loading, review Brush APIs.Step 3 (Dynamic stylus and touch behaviors) : When making a brush respond dynamically to stylus pressure, tilt, speed, direction, or procedural noise using
BrushBehaviornode trees (SourceNode,DampingNode,NoiseNode,ResponseNode,TargetNode,PolarTargetNode), you MUST follow brush-behaviors.md.Step 4 (Textures and serialization) : When adding
BrushPaint.TilingTextureorBrushPaint.StampingTexturelayers, implementingTextureBitmapStore, or encoding and decoding customBrushFamilydefinitions (BrushFamily.encodeanddecode,AndroidBrushFamilySerialization,BrushFamilyDecodeCallback), you MUST follow textures-and-serialization.md. Inform the user which texture image files (such asapp/src/main/res/drawable-nodpi/pencil_grain.png) to add to their project and register inTextureBitmapStore.Step 5 (Complete brush recipes) : When building a complete pressure pen, calligraphy nib, shading pencil, watercolor wash, or multi-coat shadow brush from scratch, start from the copy-ready implementations in examples.md.
Compose drawing surface, eraser, or persistence : For Compose drawing surface setup,
InProgressStrokeswet and dry rendering, geometry-based erasing, or Room stroke persistence, suggest theink-app-builderskill.
Antipatterns
NEVER use raw
ink.proto.*builders to construct brushes---always use the public Kotlin constructors (BrushFamily,BrushCoat,BrushTip,BrushPaint,BrushBehaviorfromandroidx.ink.brush.*).NEVER manually scale stroke width in a touch listener for pressure or tilt sensitivity---use
BrushBehaviormappingSourceNode.Source.NORMALIZED_PRESSUREorTILT_IN_RADIANStoTargetNode.Target.SIZE_MULTIPLIERorWIDTH_MULTIPLIER.NEVER use manual
Canvasbitmap stamping orBitmapShaderfor textured brushes---useBrushPaint.TilingTextureorBrushPaint.StampingTexturewith aTextureBitmapStore.NEVER use
BlendMode.SRC_OVERon the final (or only)TextureLayer---useBlendMode.MODULATE,DST_IN,DST_OUT,SRC_ATOP, orSRC_INso edge anti-aliasing andOPACITY_MULTIPLIERbehaviors aren't overridden.NEVER serialize
BrushFamilyas JSON, Gson, Moshi, orParcelable---always useBrushFamily.encodeandBrushFamily.decodeorAndroidBrushFamilySerializationfromandroidx.ink.storage.NEVER implement manual Bézier (
quadTo,cubicTo) smoothing ---configureBrushFamily.InputModel.SlidingWindowModelfor input smoothing andDampingNodefor behavior smoothing.NEVER use
Random.nextFloatin draw loops for organic stroke wobble---attach aNoiseNodevaried over stroke distance inBrushBehavior.
Files
- ATTRIBUTION.mdAdded by AutoGineer1009 B
- LICENSELicence file added by AutoGineer11.1 KiB
- SKILL.md7.2 KiB
- references/android/develop/ui/compose/touch-input/stylus-input/ink-api-brush-apis.md5.0 KiB
- references/brush-behaviors.md10.8 KiB
- references/brush-structure.md9.9 KiB
- references/examples.md11.8 KiB
- references/textures-and-serialization.md7.6 KiB
references/textures-and-serialization.md
Reference for adding BrushPaint.TilingTexture and BrushPaint.StampingTexture
layers with TextureBitmapStore, and encoding or decoding custom BrushFamily
definitions (androidx.ink 1.1.0-alpha03 and higher).
TextureBitmapStore and texture assets
androidx.ink doesn't bundle texture image assets. When generating a textured
brush, inform the user to add the referenced PNG or WebP texture file to their
project (such as app/src/main/res/drawable-nodpi/pencil_grain.png to prevent
density scaling) and return its Bitmap from TextureBitmapStore. If
TextureBitmapStore[clientTextureId] returns null, the stroke silently
renders as a flat, untextured fill.
class CustomBrushTextureStore(context: Context) : TextureBitmapStore {
private val resources = context.resources
private val textureResources: Map<String, Int> = mapOf(
"pencil-grain" to R.drawable.pencil_grain,
"watercolor-wash" to R.drawable.watercolor_wash,
)
private val loadedBitmaps = mutableMapOf<String, Bitmap>()
private val _generation = MutableStateFlow(0)
val generation: StateFlow<Int> = _generation.asStateFlow()
override operator fun get(clientTextureId: String): Bitmap? {
return loadedBitmaps.getOrPut(clientTextureId) {
textureResources[clientTextureId]?.let { resId ->
BitmapFactory.decodeResource(resources, resId)
} ?: return null
}
}
fun registerBitmap(textureId: String, bitmap: Bitmap) {
loadedBitmaps[textureId] = bitmap
_generation.update { it + 1 }
}
}<br />
When generation increments after loading a texture dynamically (such as from a
decoded .brush stream), recreate CanvasStrokeRenderer with
remember(textureStore, generation) and re-key InProgressStrokes with
key(generation) so cached BitmapShader instances refresh.
TextureLayer subclasses (TilingTexture and StampingTexture)
In 1.1.0-alpha03 and higher, BrushPaint.TextureLayer is an abstract class
with two concrete subclasses:
BrushPaint.TilingTexture: Repeats a seamless texture across stroke geometry (ideal for pencil grain, paper texture, or watercolor wash). SetsizeUnit = BrushPaint.TextureLayer.SizeUnit.BRUSH_SIZEso tile dimensions scale withBrush.size.BrushPaint.StampingTexture: Stamps a texture onto each discrete particle along a stroke (BrushTip.particleGapDistanceScale > 0forparticleGapDurationMillis > 0L). RequiresCanvasMeshRendereron Android 14 (API level 34) and higher hardwareCanvas; supply a second path-compatible fallbackBrushPaintinBrushCoat.paintPreferencesif the stroke must also render on Android 13 (API level 33) and lower or softwareCanvas(bitmap).
Choose BlendMode for texture layers
The final (or only) TextureLayer blends the texture (src) against the
brush color (dst, which carries edge anti-aliasing and per-vertex
OPACITY_MULTIPLIER). Use a blend mode whose output alpha is proportional to
Alpha_dst---such as BlendMode.MODULATE (default), BlendMode.DST_IN ,
BlendMode.DST_OUT , BlendMode.SRC_ATOP , or BlendMode.SRC_IN .
Never use BlendMode.SRC_OVER on the final TextureLayer because it overrides
edge anti-aliasing and ignores OPACITY_MULTIPLIER wherever the texture is
opaque:
fun createTexturedBrushFamily(): BrushFamily {
val grainPaint = BrushPaint(
selfOverlap = SelfOverlap.ANY,
textureLayers = listOf(
BrushPaint.TilingTexture(
clientTextureId = "pencil-grain",
sizeX = 1.0f,
sizeY = 1.0f,
sizeUnit = BrushPaint.TextureLayer.SizeUnit.BRUSH_SIZE,
blendMode = BrushPaint.TextureLayer.BlendMode.MODULATE,
),
),
colorFunctions = listOf(BrushPaint.ColorFunction.OpacityMultiplier(0.85f)),
)
return BrushFamily(
tip = BrushTip(scaleX = 1f, scaleY = 1f, cornerRounding = 1f),
paint = grainPaint,
)
}<br />
Serialize and deserialize custom BrushFamily definitions
androidx.ink.storage provides two equivalent gzipped-protobuf serialization
APIs (unannotated in 1.1.0-alpha02 and higher; requires
@OptIn(ExperimentalInkCustomBrushApi::class) only on 1.0.0 stable):
Kotlin extensions :
brushFamily.encode(outputStream, textureBitmapStore)andBrushFamily.decode(inputStream, maxVersion, getClientTextureId).Java-friendly
@JvmStaticmethods :AndroidBrushFamilySerialization.encodeandAndroidBrushFamilySerialization.decode.
Save and load a BrushFamily with embedded textures
When decoding with a texture callback in 1.1.0-alpha, always wrap the lambda
in BrushFamilyDecodeCallback { textureId, bitmap -> ... } to disambiguate
from the multiplatform OnDecodeTexturePngBytes overload. Pass
maxVersion = Version.MAX_SUPPORTED for production brushes or
Version.DEVELOPMENT when testing experimental brush features:
suspend fun saveCustomBrushToFile(
context: Context,
uri: Uri,
brushFamily: BrushFamily,
textureBitmapStore: TextureBitmapStore,
) = withContext(Dispatchers.IO) {
context.contentResolver.openOutputStream(uri)?.use { outputStream ->
brushFamily.encode(outputStream, textureBitmapStore)
}
}
suspend fun loadCustomBrushFromFile(
inputStream: InputStream,
textureStore: CustomBrushTextureStore,
allowDevelopmentFeatures: Boolean = false,
): BrushFamily = withContext(Dispatchers.IO) {
val maxVersion = if (allowDevelopmentFeatures) {
Version.DEVELOPMENT
} else {
Version.MAX_SUPPORTED
}
inputStream.use { stream ->
BrushFamily.decode(
input = stream,
maxVersion = maxVersion,
getClientTextureId = BrushFamilyDecodeCallback { textureId, bitmap ->
if (bitmap != null) {
textureStore.registerBitmap(textureId, bitmap)
}
textureId
},
)
}
}<br />
Store custom brushes in a Room database (BLOB)
Persist encoded BrushFamily bytes in a ColumnInfo.BLOB ByteArray column:
@Entity(tableName = "custom_brushes")
data class CustomBrushEntity(
@PrimaryKey val name: String,
@ColumnInfo(typeAffinity = ColumnInfo.BLOB)
val brushBytes: ByteArray,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is CustomBrushEntity) return false
return name == other.name && brushBytes.contentEquals(other.brushBytes)
}
override fun hashCode(): Int = 31 * name.hashCode() + brushBytes.contentHashCode()
}
fun encodeBrushForDatabase(
brushFamily: BrushFamily,
textureBitmapStore: TextureBitmapStore = TextureBitmapStore { null },
): ByteArray {
return ByteArrayOutputStream().use { stream ->
brushFamily.encode(stream, textureBitmapStore)
stream.toByteArray()
}
}<br />
Common pitfalls
Instantiating abstract
BrushPaint.TextureLayerdirectly : In1.1.0-alpha03and higher, instantiateBrushPaint.TilingTextureorBrushPaint.StampingTexture(SizeUnit,BlendMode, andWrapremain nested onBrushPaint.TextureLayer.*, whileOriginis nested onBrushPaint.TilingTexture.Origin).Passing an untyped trailing lambda to
BrushFamily.decode: Kotlin can't disambiguate betweenBrushFamilyDecodeCallback(Bitmap?) andOnDecodeTexturePngBytes(ByteArray?). Always wrap withBrushFamilyDecodeCallback { id, bitmap -> ... }.Oversized texture bitmaps : Keep tiled textures around 256×256 or 512×512 pixels in
res/drawable-nodpi/to avoid unnecessary GPU memory consumption.
Requirements and compatibility
Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta
“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.
Needs: Needs Node.js
Security
No issues found by our static scan· No issues found
A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.
Attribution and licence
- Created by
- Google LLC
- Publisher
- Android (Google) (Official)
- Distributed by
- Android (Google)
- Source
- android/skills · jetpack-compose/ink/ink-custom-brush-builder · commit bf68e2d
- Licence
- Apache License 2.0 (redistribution allowed)
- LICENSE (added by AutoGineer from LICENSE.txt)
- ATTRIBUTION.md (written by AutoGineer)
- Synced
AutoGineer is not affiliated with or endorsed by Google LLC or Android (Google).
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download ink-custom-brush-builder.zip