Valerii Kuznietsov
Valerii Kuznietsov

Reputation: 91

How to enable Android CameraX Vendor extensions?

I'm trying to build a camera app based on CameraX and want to enable Bokeh (Blur) effect for the camera preview. This might be done by CameraX extensions, but how to enable them?

I've read the article about Vendor extensions at Android Developer Docs. I've tried to reuse their approach, but classes shown at the example are not included at CameraX alpha-02

import androidx.camera.extensions.BokehExtender;

void onCreate() {
    // Create a Builder same as in normal workflow.
    ImageCaptureConfig.Builder builder = new ImageCaptureConfig.Builder();

    // Create a Extender object which can be used to apply extension
    // configurations.
    BokehImageCaptureExtender bokehImageCapture = new
            BokehImageCaptureExtender(builder);

    // Query if extension is available (optional).
    if (bokehImageCapture.isExtensionAvailable()) {
        // Enable the extension if available.
        bokehImageCapture.enableExtension();
    }

    // Finish constructing configuration with the same flow as when not using
    // extensions.
    ImageCaptureConfig config = builder.build();
    ImageCapture useCase = new ImageCapture(config);
    CameraX.bindToLifecycle((LifecycleOwner)this, useCase);
}

I expected that BokehImageCaptureExtender will be imported, but looks like it's still not provided. And the whole package androidx.camera.extensions is missing.

This classes could be found at the official AndroidX git repository but it's hard to setup it without importing the full AndroidX project.

Upvotes: 2

Views: 3763

Answers (3)

Rishabh Jain
Rishabh Jain

Reputation: 155

Android CameraX extensions are only present in version: "1.0.0-alpha01".

Downgrade your camera version: //Camera Jetpack Library

def camerax_version = "1.0.0-alpha01"
implementation "androidx.camera:camera-core:$camerax_version"
implementation "androidx.camera:camera-camera2:$camerax_version"
implementation "androidx.camera:camera-extensions:$camerax_version"

Upvotes: 1

Wasim Ansari
Wasim Ansari

Reputation: 475

Extension are still not available on google maven https://dl.google.com/dl/android/maven2/index.html

Refer to this thread, https://stackoverflow.com/a/57177147/11861734

Upvotes: 0

Brhaka
Brhaka

Reputation: 1642

I just noted editing your question and looking here take the Code Sample you showed is Java, but you put Kotlin as identifier. Make sure that you are using the correct language. This might be the problem.

This is the Kotlin sample from Android Developer Docs:

import androidx.camera.extensions.BokehExtender

fun onCreate() {
    // Create a Builder same as in normal workflow.
    val builder = ImageCaptureConfig.Builder()

    // Create a Extender object which can be used to apply extension
    // configurations.
    val bokehImageCapture = BokehImageCaptureExtender.create(builder)

    // Query if extension is available (optional).
    if (bokehImageCapture.isExtensionAvailable()) {
        // Enable the extension if available.
        bokehImageCapture.enableExtension()
    }

    // Finish constructing configuration with the same flow as when not using
    // extensions.
    val config = builder.build()
    val useCase = ImageCapture(config)
    CameraX.bindToLifecycle(this as LifecycleOwner, useCase)
}

This is the Java sample from Android Developer Docs:

import androidx.camera.extensions.BokehExtender;

void onCreate() {
    // Create a Builder same as in normal workflow.
    ImageCaptureConfig.Builder builder = new ImageCaptureConfig.Builder();

    // Create a Extender object which can be used to apply extension
    // configurations.
    BokehImageCaptureExtender bokehImageCapture = new
            BokehImageCaptureExtender(builder);

    // Query if extension is available (optional).
    if (bokehImageCapture.isExtensionAvailable()) {
        // Enable the extension if available.
        bokehImageCapture.enableExtension();
    }

    // Finish constructing configuration with the same flow as when not using
    // extensions.
    ImageCaptureConfig config = builder.build();
    ImageCapture useCase = new ImageCapture(config);
    CameraX.bindToLifecycle((LifecycleOwner)this, useCase);
}

Upvotes: 0

Related Questions