Giter VIP home page Giter VIP logo

camposer's Introduction

Camposer

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!


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.

camposer's People

Contributors

chrishoekstra avatar leonardorpaixao avatar mgrazianoc avatar ujizin avatar vanshg avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.