Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

License

NotificationsYou must be signed in to change notification settings

androiddevnotesforks/Capturable

 
 

Repository files navigation

Capturable

🚀A Jetpack Compose utility library for converting Composable content into Bitmap image 🖼️.
Made with ❤️ for Android Developers and Composers

BuildMaven Central

💡Introduction

In the previous View system, drawing Bitmap Image fromView was very straightforward. But that's not the case with Jetpack Compose since it's different in many aspects from previous system. This library helps easy way to achieve the same results.

🚀 Implementation

You can check/app directory which includes example application for demonstration.

Gradle setup

Inbuild.gradle of app module, include this dependency

dependencies {    implementation"dev.shreyaspatil:capturable:2.1.0"}

You can find latest version and changelogs in thereleases.

Usage

1. Setup the controller

To be able to capture Composable content, you need instance ofCaptureController by which you can decide when to capture the content. You can get the instance as follow.

@ComposablefunTicketScreen() {val captureController= rememberCaptureController()}

rememberCaptureController() is a Composable function.

2. Add the content

The component which needs to be captured, acapturable() Modifier should be applied on that @Composable component as follows.

@ComposablefunTicketScreen() {val captureController= rememberCaptureController()// Composable content to be captured.// Here, everything inside below Column will be get capturedColumn(modifier=Modifier.capturable(captureController)) {MovieTicketContent(...)    }}

3. Capture the content

To capture the content, useCaptureController#captureAsync() as follows.

// Example: Capture the content when button is clickedval scope= rememberCoroutineScope()Button(onClick= {// Capture content    scope.launch {val bitmapAsync= captureController.captureAsync()try {val bitmap= bitmapAsync.await()// Do something with `bitmap`.        }catch (error:Throwable) {// Error occurred, do something.        }    }}) {... }

On calling this method, request for capturing the content will be sent andImageBitmap will bereturned asynchronously.This method is safe to be called from Main thread.

📄 API Documentation

Visit the API documentation of this library to get more information in detail.


🙋‍♂️ Contribute

Readcontribution guidelines for more information regarding contribution.

💬 Discuss?

Have any questions, doubts or want to present your opinions, views? You're always welcome. You canstart discussions.

📝 License

MIT LicenseCopyright (c) 2022 Shreyas PatilPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, 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 THESOFTWARE.

About

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

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin100.0%

[8]ページ先頭

©2009-2025 Movatter.jp