You configure each CameraX use case to control different aspects of the use case's operations.
For example, with the image capture use case, you can set a target aspect ratio and a flash mode. The following code shows one example:
Kotlin
val imageCapture = ImageCapture.Builder() .setFlashMode(...) .setTargetAspectRatio(...) .build()
Java
ImageCapture imageCapture = new ImageCapture.Builder() .setFlashMode(...) .setTargetAspectRatio(...) .build();
In addition to configuration options, some use cases expose APIs to dynamically alter settings after the use case has been created. For information about configuration that is specific to the individual use cases, see Implement a preview, Analyze images, and Image capture.
CameraXConfig
For simplicity, CameraX has default configurations such as internal executors
and handlers that are suitable for most usage scenarios. However, if your
application has special requirements or prefers to customize those
configurations, CameraXConfig
is the interface for that purpose.
With CameraXConfig
, an application can do the following:
- Optimize startup latency with
setAvailableCameraLimiter()
. - Provide the application's executor to CameraX with
setCameraExecutor()
. - Replace the default scheduler handler with
setSchedulerHandler()
. - Change the logging level with
setMinimumLoggingLevel()
.
Usage Model
The following procedure describes how to use CameraXConfig
:
- Create a
CameraXConfig
object with your customized configurations. - Implement the
CameraXConfig.Provider
interface in yourApplication
, and return yourCameraXConfig
object in