Convert Figma logo to code with AI

CameraKit logocamerakit-android

Library for Android Camera 1 and 2 APIs. Massively increase stability and reliability of photo and video capture on all Android devices.

5,357
878
5,357
162

Top Related Projects

📸 A well documented, high-level Android interface that makes capturing pictures and videos easy, addressing all of the common issues and needs. Real-time filters, gestures, watermarks, frame processing, RAW, output of any size.

[DEPRECATED] Easily integrate Camera features into your Android app

Making Camera for Android more friendly. 📸

PhotoView For Fresco

Image Cropping Library for Android, optimized for Camera / Gallery.

Quick Overview

CameraKit-Android is an open-source camera library for Android that simplifies the process of integrating camera functionality into Android applications. It provides a high-level API for camera operations, including capturing photos and videos, with support for various camera features and optimizations.

Pros

  • Easy to integrate and use, with a simple API for common camera operations
  • Supports both front and back cameras, as well as various camera features like flash and focus modes
  • Optimized for performance and memory usage
  • Actively maintained and regularly updated

Cons

  • May have limitations for advanced camera features or specific device requirements
  • Documentation could be more comprehensive for some advanced use cases
  • Potential learning curve for developers new to camera APIs

Code Examples

  1. Initializing CameraKit:
val cameraKitView = findViewById<CameraKitView>(R.id.camera)
cameraKitView.onCreate(savedInstanceState)
  1. Capturing a photo:
cameraKitView.captureImage { cameraKitView, photo ->
    // Handle the captured photo
    val savedPhoto = File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "photo.jpg")
    photo.saveAsJPEG(savedPhoto)
}
  1. Toggling camera facing:
cameraKitView.toggleFacing()
  1. Setting camera properties:
cameraKitView.apply {
    flash = CameraKit.FLASH_AUTO
    focus = CameraKit.FOCUS_TAP
    pinchToZoom = true
}

Getting Started

  1. Add the dependency to your app's build.gradle:
dependencies {
    implementation 'com.camerakit:camerakit:1.0.0-beta3.11'
    implementation 'com.camerakit:jpegkit:0.1.0'
}
  1. Add CameraKitView to your layout:
<com.camerakit.CameraKitView
    android:id="@+id/camera"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true" />
  1. Initialize and manage CameraKitView in your Activity or Fragment:
class MainActivity : AppCompatActivity() {
    private lateinit var cameraKitView: CameraKitView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        cameraKitView = findViewById(R.id.camera)
        cameraKitView.onCreate(savedInstanceState)
    }

    override fun onStart() {
        super.onStart()
        cameraKitView.onStart()
    }

    override fun onResume() {
        super.onResume()
        cameraKitView.onResume()
    }

    override fun onPause() {
        cameraKitView.onPause()
        super.onPause()
    }

    override fun onStop() {
        cameraKitView.onStop()
        super.onStop()
    }

    override fun onDestroy() {
        cameraKitView.onDestroy()
        super.onDestroy()
    }
}

Competitor Comparisons

📸 A well documented, high-level Android interface that makes capturing pictures and videos easy, addressing all of the common issues and needs. Real-time filters, gestures, watermarks, frame processing, RAW, output of any size.

Pros of CameraView

  • More actively maintained with frequent updates and bug fixes
  • Offers a wider range of features, including video recording and frame processing
  • Better documentation and examples for easier integration

Cons of CameraView

  • Larger library size, which may impact app size
  • Steeper learning curve due to more complex API

Code Comparison

CameraView:

cameraView.setLifecycleOwner(this)
cameraView.addCameraListener(object : CameraListener() {
    override fun onPictureTaken(result: PictureResult) {
        // Handle the captured image
    }
})
cameraView.takePicture()

CameraKit:

cameraKitView.captureImage { cameraKitView, picture ->
    // Handle the captured image
}

Key Differences

  • CameraView provides more granular control over camera settings and behaviors
  • CameraKit offers a simpler API for basic camera operations
  • CameraView supports both Kotlin and Java, while CameraKit is primarily Java-focused
  • CameraView has better support for modern Android features and architectural components

Conclusion

CameraView is more feature-rich and actively maintained, making it suitable for complex camera implementations. CameraKit, while simpler, may be sufficient for basic camera functionality but lacks some advanced features and recent updates.

[DEPRECATED] Easily integrate Camera features into your Android app

Pros of cameraview

  • Developed and maintained by Google, potentially offering better long-term support and integration with Android ecosystem
  • More frequent updates and active development
  • Comprehensive documentation and examples provided

Cons of cameraview

  • Limited features compared to camerakit-android
  • Less flexibility in customization options
  • Smaller community and fewer third-party contributions

Code Comparison

cameraview:

CameraView cameraView = findViewById(R.id.camera);
cameraView.setLifecycleOwner(this);
cameraView.addCameraListener(new CameraListener() {
    @Override
    public void onPictureTaken(PictureResult result) {
        // Process the captured image
    }
});

camerakit-android:

CameraKitView cameraKitView = findViewById(R.id.camera);
cameraKitView.setCameraListener(new CameraKitEventListener() {
    @Override
    public void onImage(CameraKitImage image) {
        // Process the captured image
    }
});

Both libraries offer similar basic functionality for capturing images, but camerakit-android provides more advanced features and customization options. cameraview benefits from Google's backing and potentially better integration with the Android ecosystem, while camerakit-android offers greater flexibility and a wider range of features for developers who need more control over camera functionality.

Making Camera for Android more friendly. 📸

Pros of Fotoapparat

  • Written in Kotlin, offering modern language features and better null safety
  • Provides a more flexible and customizable API for camera operations
  • Supports both Camera1 and Camera2 APIs, with automatic selection based on device capabilities

Cons of Fotoapparat

  • Less actively maintained compared to CameraKit-Android
  • Smaller community and fewer resources available for troubleshooting
  • May have a steeper learning curve for developers new to Kotlin

Code Comparison

Fotoapparat:

val fotoapparat = Fotoapparat(
    context = this,
    view = cameraView,
    scaleType = ScaleType.CenterCrop
)

fotoapparat.start()
fotoapparat.takePicture()

CameraKit-Android:

cameraKitView.start();
cameraKitView.captureImage(new CameraKitView.ImageCallback() {
    @Override
    public void onImage(CameraKitView view, byte[] photo) {
        // Handle the captured image
    }
});

Both libraries offer straightforward APIs for basic camera operations, but Fotoapparat's Kotlin-based approach may be more appealing to developers working with modern Android projects. CameraKit-Android's Java implementation might be more familiar to developers with traditional Android experience.

PhotoView For Fresco

Pros of PhotoDraweeView

  • Specialized for image viewing and zooming, offering a more focused and optimized solution for this specific use case
  • Built on top of Fresco, leveraging its powerful image loading and caching capabilities
  • Lightweight and easy to integrate into existing projects

Cons of PhotoDraweeView

  • Limited to image viewing functionality, lacking camera capture features
  • Requires Fresco as a dependency, which may increase app size and complexity
  • Less actively maintained compared to CameraKit

Code Comparison

PhotoDraweeView:

PhotoDraweeView photoDraweeView = findViewById(R.id.photo_drawee_view);
photoDraweeView.setPhotoUri(Uri.parse("https://example.com/image.jpg"));
photoDraweeView.setMaximumScale(5.0f);

CameraKit:

CameraView cameraView = findViewById(R.id.camera_view);
cameraView.setCameraListener(new CameraListener() {
    @Override
    public void onPictureTaken(byte[] picture) {
        // Process captured image
    }
});

The code snippets highlight the different focus areas of the two libraries. PhotoDraweeView is centered around displaying and manipulating images, while CameraKit provides functionality for capturing photos and videos using the device's camera.

Image Cropping Library for Android, optimized for Camera / Gallery.

Pros of Android-Image-Cropper

  • Specialized in image cropping functionality, offering more advanced cropping features
  • Lightweight and focused on a single task, potentially easier to integrate for specific cropping needs
  • Provides a customizable UI for image cropping, allowing users to interact directly with the cropping process

Cons of Android-Image-Cropper

  • Limited to image cropping, lacking the comprehensive camera functionality of camerakit-android
  • May require additional libraries or components for full camera capture and processing pipeline
  • Less actively maintained, with fewer recent updates compared to camerakit-android

Code Comparison

Android-Image-Cropper:

CropImage.activity(imageUri)
    .setGuidelines(CropImageView.Guidelines.ON)
    .setAspectRatio(1, 1)
    .start(this);

camerakit-android:

cameraKitView.captureImage(new CameraKitView.ImageCallback() {
    @Override
    public void onImage(CameraKitView cameraKitView, byte[] capturedImage) {
        // Process captured image
    }
});

Android-Image-Cropper focuses on image manipulation after capture, while camerakit-android provides a more comprehensive camera capture solution. The choice between them depends on whether you need a full camera implementation or specifically image cropping functionality.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CameraKit Header

Google Play Link Join Spectrum Buddy.Works

CameraKit helps you add reliable camera to your app quickly. Our open source camera platform provides consistent capture results, service that scales, and endless camera possibilities.

With CameraKit you are able to effortlessly do the following:

  • Image and video capture seamlessly working with the same preview session.
  • Automatic system permission handling.
  • Automatic preview scaling.
    • Create a CameraView of any size (not just presets!).
    • Automatic output cropping to match your CameraView bounds.
  • Multiple capture methods.
    • METHOD_STANDARD: an image captured normally using the camera APIs.
    • METHOD_STILL: a freeze frame of the CameraView preview (similar to SnapChat and Instagram) for devices with slower cameras.
    • METHOD_SPEED: automatic capture method determination based on measured speed.
  • Built-in continuous focus.
  • Built-in tap to focus.
  • Built-in pinch to zoom.

Sponsored By

Expensify Buddy.Works

Trusted By

InFitting GooseChase Alpha Apps Expensify

 

Get The Most From CameraKit

There are currently two versions of CameraKit that we support, v1.0.0-beta3.X and v0.13.X.

If photo is your only need, try out the latest and greatest CameraKit features with v1.0.0-beta3.11. Our beta3.11 release does not yet support video, but that feature is coming!

In the meantime, if your application requires video we recommend sticking with v0.13.4; the latest stable release with video implementation.

Use CaseVersionNotesDocumentation Link
Photo onlyv1.0.0-beta3.11The latest and greatest CameraKit has to offer. Video support coming soon!camerakit.io/docs/beta3.11
Photo and Videov0.13.4Stable build with full photo and video supportcamerakit.io/docs/0.13.4

Documentation Site

Setup instructions for 1.0.0-beta3.11 are below. To see the full documentation head over to our website, camerakit.io/docs.

Setup

To include CameraKit in your project, add the following to your app level build.gradle.

dependencies {
    implementation 'com.camerakit:camerakit:1.0.0-beta3.11'
    implementation 'com.camerakit:jpegkit:0.1.0'
    implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.0'
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.0.0'
}

Usage

Create a CameraKitView in your layout as follows:

<com.camerakit.CameraKitView
    android:id="@+id/camera"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true"
    android:keepScreenOn="true"   <!-- keep screen awake while CameraKitView is active -->
    app:camera_flash="auto"
    app:camera_facing="back"
    app:camera_focus="continuous"
    app:camera_permissions="camera" />

Then create a new CameraKitView object in your Activity and override the following methods.

private CameraKitView cameraKitView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    cameraKitView = findViewById(R.id.camera);
}

@Override
protected void onStart() {
    super.onStart();
    cameraKitView.onStart();
}

@Override
protected void onResume() {
    super.onResume();
    cameraKitView.onResume();
}

@Override
protected void onPause() {
    cameraKitView.onPause();
    super.onPause();
}

@Override
protected void onStop() {
    cameraKitView.onStop();
    super.onStop();
}

@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    cameraKitView.onRequestPermissionsResult(requestCode, permissions, grantResults);
}

ProGuard

If using ProGuard, add the following rules:

-dontwarn com.google.android.gms.**
-keepclasseswithmembers class com.camerakit.preview.CameraSurfaceView {
    native <methods>;
}

License

CameraKit is MIT License