Skip to content

jmseb3/Capturable

 
 

Capturable

Capturable

Compose Multiplatform utility library for capturing Composable content as ImageBitmap.

Thanks to @PatilShreyas for the original inspiration.

Maven Central Version Kotlin Compose Multiplatform License badge-android badge-ios badge-desktop badge-js

Introduction

Capturable makes it easy to capture Compose UI content into bitmap images across platforms.

Modules

  • io.github.jmseb3:capturable: core capture API (CaptureController, Modifier.capturable)
  • io.github.jmseb3:capturableExtension: optional save/share helpers built on top of FileKit

Installation

Version catalog (libs.versions.toml)

[versions]
capturable = "2.0.2"

[libraries]
capturable = { module = "io.github.jmseb3:capturable", version.ref = "capturable" }
capturable-extension = { module = "io.github.jmseb3:capturableExtension", version.ref = "capturable" }
dependencies {
    implementation(libs.capturable)
    implementation(libs.capturable.extension)
}

Direct dependency

dependencies {
    implementation("io.github.jmseb3:capturable:2.0.2")
    implementation("io.github.jmseb3:capturableExtension:2.0.2")
}

Latest versions and changelog: Releases

Quick Start

1. Create a controller

@Composable
fun TicketScreen() {
    val captureController = rememberCaptureController()
}

2. Mark target content as capturable

@Composable
fun TicketScreen() {
    val captureController = rememberCaptureController()

    Column(modifier = Modifier.capturable(captureController)) {
        MovieTicketContent(...)
    }
}

3. Capture asynchronously

val scope = rememberCoroutineScope()

Button(onClick = {
    scope.launch {
        runCatching { captureController.captureAsync().await() }
            .onSuccess { bitmap -> /* use bitmap */ }
            .onFailure { error -> error.printStackTrace() }
    }
}) { ... }

Extension (Save/Share)

If you need captureAsyncAndSave or captureAsyncAndShare, use capturableExtension.

It depends on FileKit. Follow the FileKit setup guide.

Android initialization example:

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        FileKit.init(this)
    }
}
Platform captureAsyncAndSave captureAsyncAndShare
Android
iOS
JVM
JS
WASM

Sample App

Example app source lives in sample/.

  • Desktop: ./gradlew :sample:desktopApp:run
  • JS browser: ./gradlew :sample:webApp:jsBrowserDevelopmentRun --continue
  • WASM browser: ./gradlew :sample:webApp:wasmJsBrowserDevelopmentRun --continue
  • Android: run sample:androidApp from Android Studio
  • iOS: open sample/iosApp/iosApp.xcodeproj in Xcode and run

Preview

Android Android Screenshot
iOS iOS Screenshot
Desktop

Desktop

JS

JS

WASM

WASM

Contribute

Read contribution guidelines for details.

License

MIT License

Copyright (c) 2022 Shreyas Patil
Copyright (c) 2024 WonDDak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

Compose Multiplatform utility library for capturing Composable content and transforming it into Bitmap Image🖼️

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Kotlin 100.0%