A Jetpack Compose Painting Helper Library (Inspired by Drawbox) using Jetpack Compose Canvas with multiple features and flexibility. It also supprots Compose Multiform for Android, iOS, Desktop and Web (Wasm).
Inspired by Drawbox
Add this to your project level "build.gradle" or in newer versions of gradle in "settings.gradle" under repositories section:
repositories {
mavenCentral()
}
Add this to your module level build.gradle file:
implementation 'tech.dev-scion:canvaspainter:<latest-version>'
If you are using compose multiplatform add it to commonMain sourceset's dependencies section:
implementation("tech.dev-scion:canvaspainter:<latest-version>")
Replace TAG with library version
Create PainterController Object directly or by using below composable.
val painterController = rememberCanvasPainterController(
maxStrokeWidth = 200f,
showToolbar = true,
Color.Red
)
Direct Approach
val painterController = remember {
PainterController().apply {
maxStrokeWidth = 100f //Max Stroke a user can set using stroke selection slider
showToolbar = true,
)
}
}
Add CanvasPainter composable to your layout
CanvasPainter(
Modifier.fillMaxSize(),
painterController
)
Other PainterController functions:
painterController.getCanvasAsImageBitmap() //You can get the bitmap of canvas using this function
ImageBitmap.toByteArray() //This is an extension function for ImageBitmap included in project to convert ImageBitmap to ByteArray.
Note: ImageBitmap.toByteArray() returns null for web. Its implementation is pending.
Libraries Used by CanvasPainter: colorpicker-compose