A Jetpack Compose Painting Helper Library (Inspired by Drawbox) using Jetpack Compose Canvas with multiple features and flexibility 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:TAG'
Replace TAG with library version
Create PainterController Object directly or by using below composable.
val painterController = rememberCanvasPainterController(
maxStrokeWidth = 200f,
showToolbar = true, storageOptions = StorageOptions(shouldSaveByDefault = false),//setting false will return bitmap in below callback
Color.Red
) {
// This will only be called when you set "shouldSaveByDefault = false" in storage options
}
Direct Approach
val painterController = remember {
PainterController().apply {
maxStrokeWidth = 100f //Max Stroke a user can set using stroke selection slider
showToolbar = true
//Optional
storageOptions = StorageOptions(
"My Painter", //Your directory name where images should be saved
shouldSaveByDefault = true // "true" means you want to save image on clicking save and "false" want a bitmap returned when clicked save
),
onBitmapGenerated = {
//Bitmap is returned here. This will only be called when you set "shouldSaveByDefault = false" in storage options
})
}
}
Add CanvasPainter composable to your layout
CanvasPainter(
Modifier.fillMaxSize(),
painterController
)