Camposer

282 stars
by Lucas Ujizin

Camera Library for Android Jetpack Compose with easy camera control and image capture.

View on GitHub

Documentation

Camposer

README image

License API Profile Dokka

Tired to use a camera in Jetpack Compose with interoperability? Then Camposer was made for you.
A camera library totally in Jetpack Compose which supports taking photos, recording videos, flash modes, zoom ratio, and among others!


README image
README image

Check out the Sample project

Gradle

Add dependency to your build.gradle and sync your project

implementation 'io.github.ujizin:camposer:<version>'

How to use

To add CameraPreview composable, just use the example below:

val cameraState = rememberCameraState()
var camSelector by rememberCamSelector(CamSelector.Back)
CameraPreview(
  cameraState = cameraState,
  camSelector = camSelector,
) {
  // Camera Preview UI
}

Taking pictures

To take picture use CameraState and call takePicture method from it.

// Using content values
cameraState.takePicture(contentValues, mediaURI) { result ->
  /* ... */
}

// Using files
cameraState.takePicture(file) { result -> /* ... */ }

Recording videos

Change the capture mode for CaptureMode.Video on CameraPreview and call toggleRecording method twice for stop recording, or use startRecording and stopRecording separately

// Using content values
cameraState.startRecording()
cameraState.stopRecording(contentValues, mediaURI) { result ->
  /* ... */
}

// Using file
cameraState.startRecording()
cameraState.stopRecording(file) { result -> /* ... */ }

// Using content values + toggle
cameraState.toggleRecording(contentValues, mediaURI) { result ->
  /* ... */
}

// Using files + toggle
cameraState.toggleRecording(file) { result -> /* ... */ }

Switch cameras

To switch cameras, you have to add camSelector to your CameraPreview composable, as shown previously, after implementation, just need to change its state.

// Use front camera
camSelector = CamSelector.Front

// Use back camera
camSelector = CamSelector.Back

// Inverse camera selector
camSelector = camSelector.inverse

Other configurations

If you want to use other configurations, you can see our wiki.

Have a fun code()!

License

Copyright 2022 ujizin (Lucas Yuji) 

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Dispatch Newsletter
Be the first to discover new Compose libraries
Curated Insights
Digest in 5 minutes or less
Android Analysis
Entertaining takes on happenings
Insider Tips
From top Android developers
Hidden Gems
You won't find elsewhere
"
"Dispatch is truly a newsletter, not just a digest of links. Vinay adds a delightful touch of humor and personality to a thoughtful analysis of the Android happenings of the month. I always learn something just by skimming it that makes me want to bookmark the issue now and dig deeper later."
— Zach Klippenstein
ex-Jetpack Compose Team @ Google, Square, Amazon
Join thousands of Android devs who look forward to Dispatch every week