Skip to content

Camera and Video Library for Kotlin Multiplatform. 📸

Notifications You must be signed in to change notification settings

estivensh/kaptureX

Repository files navigation

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.

About

Camera and Video Library for Kotlin Multiplatform. 📸

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages