Camposer: Jetpack Compose camera library for Android
source link: https://medium.com/@lucasyujideveloper/camposer-camera-library-using-jetpack-compose-for-android-3af63220fa00
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Camposer: Jetpack Compose camera library for Android
Tired to use a camera library with interoperability using Jetpack Compose? so Camposer was made for you, a camera library only using Jetpack Compose.
This story will guide you on how to implement Camposer into your project, so let’s start!
https://github.com/ujizin/Camposer/tree/main/camposer
Setup
First, you need to add a dependency, with the latest version, to your build.gradle (module):
dependencies {
implementation("io.github.ujizin:camposer:<version>")
}
How it works
Let’s begin using CameraPreview to display on UI.
Camera preview
CameraPreview
is the composable function to display the camera preview.CameraState
is not required for preview, but it’s necessary for action as taking a picture, recording videos, and for internal states (flash & image analyzer)
Switch Cameras
To switch cameras, use CamSelector.Back
or CamSelector.Front
, and it can be used with a state like the below example:
Switch camera
Taking pictures
for this, you’ll just need to use CameraState
and call takePicture
method from it, like the example below:
CaptureMode Image
Recording Video
It’s very similar to taking pictures. For this, you need to change the capture mode for CaptureMode.Video
and call toggleRecording
twice times for stop recording.
ps: you can use startRecording
and stopRecording
separately.
CaptureMode video
Other Configurations
There are a lot of other configurations on Camposer, if you want to use some of them check out the Camposer Wiki for more information!
And that’s all folks!
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK