Code Monkey home page Code Monkey logo

kapturex's Introduction

KaptureX

KaptureX is a library designed to facilitate the integration of image and video capture capabilities in multiplatform applications developed with Kotlin. This library is especially useful for those who want to create applications that support multiple platforms such as Android and iOS, providing a unified API and reusable components.

Maven Central Kotlin GitHub License badge badge badge

Status

Product Android iOS
Camera ☑️ alpha ☑️ alpha
Video ☑️ alpha ☑️ alpha
Flash ☑️ alpha ☑️ alpha

Implementation

add the dependency build.gradle.kts file:

commonMain.dependencies {
    implementation("io.github.estivensh:kaptureX:$version")
}

Basic Usage

Below is a basic example of how to use the CameraPreview component in your application:

@OptIn(ExperimentalCameraPreview::class)
@Composable
fun MyCameraScreen() {
    val cameraState = rememberCameraState()

    CameraPreview(
        cameraState = cameraState,
        camSelectorOnChanged = { newSelector ->

        },
        flashModeOnChanged = { newFlashMode ->

        },
        cameraOptionOnChanged = { newOption ->

        }
    )
}

Customizable Parameters

The CameraPreview component offers a wide variety of parameters to customize its behavior:

  • cameraState: Current camera state. Use rememberCameraState() to handle and remember the camera state

  • camSelector: Selects the camera (front or back). You can handle camera switching using camSelectorOnChanged.

  • flashMode: Configures the camera's flash mode. You can change it using flashModeOnChanged.

  • captureMode: Defines the capture mode (image or video).

  • imageCaptureMode: Sets the image capture mode (high quality or fast speed).

  • zoomRatio: CControls the zoom level. You can handle zoom changes with onZoomRatioChanged.

  • isImageAnalysisEnabled: Enables or disables real-time image analysis.

  • onPreviewStreamChanged: Callback executed when the preview stream changes.

@OptIn(ExperimentalCameraPreview::class)
@Composable
fun CameraSection(
    cameraState: CameraState,
    useFrontCamera: Boolean,
    usePinchToZoom: Boolean
) {
    var flashMode by cameraState.rememberFlashMode(FlashMode.valueOf("On"))
    var camSelector by rememberCamSelector(if (useFrontCamera) CamSelector.Front else CamSelector.Back)
    var zoomRatio by rememberSaveable { mutableStateOf(cameraState.minZoom) }
    var zoomHasChanged by rememberSaveable { mutableStateOf(false) }
    var cameraOption by rememberSaveable { mutableStateOf(CameraOption.Video) }
    val enableTorch = true
    CameraPreview(
        cameraState = cameraState,
        camSelector = camSelector,
        captureMode = cameraOption.toCaptureMode(),
        flashMode = flashMode,
        enableTorch = enableTorch,
        zoomRatio = zoomRatio,
        isPinchToZoomEnabled = usePinchToZoom,
        onZoomRatioChanged = {
            zoomHasChanged = true
            zoomRatio = it
        },
        onSwitchToFront = { _ ->

        },
        onSwitchToBack = { _ ->

        },
        camSelectorOnChanged = { camSelector = it },
        flashModeOnChanged = { flashMode = it },
        cameraOptionOnChanged = { cameraOption = it },
        cameraOption = cameraOption,
    )
}

Inspiration

This library was mostly inspired by Camposer.

Camera Library for Android Jetpack Compose. 📸✨

Find this repository useful? ❤️

Support it by joining estivensh4 for this repository. ⭐
Also follow me for my next creations! 🤩

License

Copyright 2024 Estiven Sánchez
 
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

    https://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.

kapturex's People

Contributors

estivensh avatar

Stargazers

Art Shendrik avatar  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.