Giter Club home page Giter Club 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

camposer's Issues

Can't change alpha on `CameraPreview`

please complete the following information

  • Device: Xiaomi Mi 9T Pro and Google Pixel 7 Pro
  • Android version: 12 and 13
  • Library version: 0.1.0

Describe the bug

I'm not able to make the preview transparent.

To Reproduce

        CameraPreview(
            modifier = Modifier
                .alpha(0.1f),
            cameraState = cameraState,
            camSelector = camSelector,
        ) {
            // Camera Preview UI
        }

Expected behavior

Content should be transparent

Screenshots

Are you willing to provide a PR?

Allow VideoCapture to be used with Image Analysis.

Discussed in #23

Is your feature request related to a problem? Please describe.

Add ability to use video capture and Image analysis at the same time

Describe the solution you'd like

Remove use cases conditions from camera state

Are you willing to provide a PR?

Yupi!

Add focus mode adjustment and exposure support

  1. Add long press to lock focus
  2. Exposure adjustment, when the focus mode is manual focus, can manually adjust the exposure

If I don't explain it clearly, you can open the system camera and see the focus mode and exposure adjustments

thanks

Make `CameraState` public

Is your feature request related to a problem? Please describe.
When you want to access the CameraState to record video in a Foreground Service for example, you are currently out of luck

Describe the solution you'd like
Remove the internal property

Describe alternatives you've considered

Are you willing to provide a PR?

Yes

Enabled use case problem

Hi. first of all, thanks for developing this package.
I have tested this package and it works great but I have a device which has android 6.
When I launch CameraScreen, it gives me this exception:
The selected camera does not support the enabled use cases. Please "
+ "disable use case and/or select a different camera. e.g. "
+ "#setVideoCaptureEnabled(false)
how can I solve it?
I used this:
cameraState.controller.setEnabledUseCases(CameraController.IMAGE_ANALYSIS)
but nothing changed.
any idea?

ByteArray as return on ImageCaptureResult

Would like to ask if, would be supported on future releases the raw ByteArray output? i think this a good option that there were no more file save on the storage and the user can retake a picture.

Also how do I make a retake a picture functionality?

Cheers!

Aspect Ratio support.

Is your feature request related to a problem? Please describe.
No.

Describe the solution you'd like
ImageCapture use case with Aspect Ratio support.

Describe alternatives you've considered
Most photo applications needs to control the aspect ratio of the generated image. The default available ones for the ImageCapture use case are RATIO_4_3 and RATIO_16_9.

Are you willing to provide a PR?
Yes.

Add support for UVC Camera

Is your feature request related to a problem? Please describe.
The device I used didn't have a built-in camera, it connected to an external UVC Camera via USB.
Currently, there's no way to connect UVC Camera in Camposer.

Describe the solution you'd like
Add parameter when use CamSelector, it can be the VID/PID or a UsbDevice instance.

Describe alternatives you've considered
None.

Are you willing to provide a PR?
I'm a beginner programmer and this might be too difficult for me. But I'll try to help.

Add support for Audio config

Is your feature request related to a problem? Please describe.

Currently, there's no way to disable/enable audio in Camposer

Describe the solution you'd like

Add audio config parameter when starting recording video

Describe alternatives you've considered
None.

Are you willing to provide a PR?

Yes, however, I'm waiting for release 1.3.0 stable because it'll be added the parameter on CameraController.

Image rotation issue

please complete the following information

  • Device: Samsung S8
  • Android version: Android 8
  • Library version: 0.1.0

Describe the bug

A clear and concise description of what the bug is.

To Reproduce
Capture image in portrait mode
Normal configuration and setup of camerax - here is the link of the video of the issue

https://drive.google.com/file/d/1MfzUONmr0ggrY2_bVAWNZEO6Q1GRZ7lQ/view?usp=share_link

Expected behavior

Since I captured it on portrait mode the image preview should be on portrait also

Screenshots

If applicable, add screenshots to help explain your problem.

https://drive.google.com/file/d/1MfzUONmr0ggrY2_bVAWNZEO6Q1GRZ7lQ/view?usp=share_link

Really dont know if it is a bug or not? is it camerax bug or not?
Any idea why this happening?

Thanks a lot!

Documentation example raise type mismatch

please complete the following information

Describe the bug
Following the How To Use first example, the following error message pops up:

Type mismatch.
Required: CamSelector
Found: MutableState<CamSelector>

To Reproduce
Just follow the documentation.

Expected behavior
Same behavior as expected in the documentation.

Screenshots
image
image

Are you willing to provide a PR?
I can. If I understood correctly what is the expected behavior: between CameraPreview to receive a mutableStateOf<CamSelector> or just the CamSelector, the second one is the intended one. So just fixing the documentation would be the solution.

Aspect Ratio support.

Now only support 4:3, 16:9 aspect ratio.
Hope to add full screen and 1:1 support

You know, the full screen of today's mobile phones is not 16:9, so if you are full screen, part of the content will be cropped out

Update CameraX to 1.2.2

Is your feature request related to a problem? Please describe.
This library currently uses CameraX version 1.1.0. Since then, 1.2.2 has been released (and 1.3.0 is in the works). The new version adds new features and fixes bugs

Describe the solution you'd like

  • Update the libraries to 1.2.2

Describe alternatives you've considered

  • Forcing the version to 1.2.2 in my own app crashes the SDK
  • Waiting until 1.3.0, which seems like it will have a bevy of new features

Are you willing to provide a PR?
If it's as simple as bumping the version, sure. However, there are new features in 1.2.x that may be worth integrating (such as ZERO_SHUTTER_LAG, MLKitAnalyzer

add control the exposure?

Can the functionality of manually controlling exposure be added? Add left-right swipe on the preview to control the exposure

Provide way to access underlying CameraController

Is your feature request related to a problem? Please describe.

The specific use case I'm looking to solve is to know when the camera tap-to-focus has completed. The current tap-to-focus functionality does not hook into CameraController#getTapToFocusState and seems to rely on an arbitrary delay to consider the focusing "done".

While this should theoretically be independently solvable, the more general "issue" here is the availability of the data but a restrction on access. Since CameraController is the interface to the Camera, it would be nice if that was directly exposed instead of needing native support within the library for a specific feature.

Describe the solution you'd like

It would be nice if the controller property in CameraState was publicly accessible (currently it is declared as internal)

The KDoc for the property in this library even says itself (emphasis mine): Main controller from CameraX. **useful in cases that haven't been release some feature yet**.

And yet it cannot be useful if it is not marked as public

Still can't figure out how to change aspect ratio!

Hi. There are two options we have from camerax that allow us to change aspect ration:

Preview preview = new Preview.Builder()
            .setTargetAspectRatio(AspectRatio.RATIO_4_3)
            .build();
ImageCapture imageCapture = new ImageCapture.Builder()
            .setTargetAspectRatio(AspectRatio.RATIO_4_3)
            .build();

The first one change the viewfinder ration, the second one changes the output picture ratio.
Can I change aspect ratio only for ImageCapture and not for preview?

What code should I write to change aspect ration in both cases?

I haven't found any setTargetAspectRatio lines inside library code.

CameraPreview extends over parent size on API level 24

  • Device: Emulator, Hardware profile "Small Phone" in Android studio.
  • Android version: 7 API level 24
  • Library version: 0.4.0

Describe the bug

The camera preview does not respect size constrains.
I have set the height with .height(), .weight(), .fillMaxHeight(). But nothing works. The only thing that seems to affect it is padding, but that will also affect all other screen sizes and API levels.

I have tested with API level 24 and 30 with the same screensize, and it only happens on level 24.

To Reproduce

  • Create "small phone" with API level 24
  • Create a CameraPreview

Screenshots

smallPhone

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.