Vendor extensions

CameraX provides an API for accessing device-specific vendor effects, such as bokeh, HDR, and additional functionality. The API enables you to query whether a particular extension is available on the current device and to enable the extension preferentially. That is, if the extension is available on that device, it will be enabled, and will degrade gracefully if it is not.

Vendors aren't required to provide an implementation for every effect and feature. Any capability without a vendor-provided implementation defaults to the CameraX implementation. The default implementation reports that the capability is unavailable and skip enabling it.

Enable an effect for image capture

To apply vendor extensions to CameraX use cases, create an Extender object, which allows you to configure the Builder with the settings for that effect or function. Query the extension for availability, because if an extension is unavailable the enableExtension() call will not do anything.

To implement the extension for the image capture use case, implement the corresponding image capture extender as shown in the following code sample:

Kotlin

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)
}

Java

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);
}

Disable the effect

To disable vendor extensions, create a new instance of the image capture use case or the preview use case.

Additional resources

To learn more about CameraX, consult the following additional resources.

Codelab

  • Getting Started with CameraX
  • Code sample

  • Official CameraX sample app