public abstract class CameraEffect

An effect for one or multiple camera outputs.

This API allows the implementer to inject code into CameraX pipeline and apply visual effects, such as a portrait effect. The CameraEffect class contains two types of information, the processor and the configuration.

  • The processor is an implementation of either SurfaceProcessor or ImageProcessor. It consumes original camera frames from CameraX, applies the effect, and returns the processed frames back to CameraX.
  • The configuration provides information on how the processor should be injected into the pipeline. For example, the target UseCases where the effect should be applied. It may also contain information about camera configuration. For example, the exposure level.

If CameraX fails to send frames to the CameraEffect, the error will be delivered to the app via error callbacks such as onError. If CameraEffect fails to process and return the frames, for example, unable to allocate the resources for image processing, it must throw Throwable in the processor implementation. The Throwable will be caught and forwarded to the app via error callbacks. Please see the Javadoc of the processor interfaces for details.

Extend this class to create specific effects. The Executor provided in the constructors will be used by CameraX to call the processors.

Code sample for a portrait effect that targets the PreviewUseCase:

class PortraitPreviewEffect extends CameraEffect {
    PortraitPreviewEffect() {
        super(PREVIEW, getExecutor(), getSurfaceProcessor());
    }

    private static Executor getExecutor() {
        // Returns an executor for calling the SurfaceProcessor
    }

    private static SurfaceProcessor getSurfaceProcessor() {
        // Return a SurfaceProcessor implementation that applies a portrait effect.
    }
}

Summary

Constants

static final int

Bitmask option to indicate that CameraX should apply this effect to ImageCapture.

static final int

Bitmask option to indicate that CameraX should apply this effect to Preview.

static final int

Bitmask option to indicate that CameraX should apply this effect to VideoCapture.

Constants

IMAGE_CAPTURE

public static final int IMAGE_CAPTURE = 4

Bitmask option to indicate that CameraX should apply this effect to ImageCapture.

PREVIEW

public static final int PREVIEW = 1

Bitmask option to indicate that CameraX should apply this effect to Preview.

VIDEO_CAPTURE

public static final int VIDEO_CAPTURE = 2

Bitmask option to indicate that CameraX should apply this effect to VideoCapture.

Protected constructors

Public methods

Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Last updated 2025-05-15 UTC.