ImageCaptureScope


@CameraXDsl
class ImageCaptureScope


Scope class for ImageCapture configuration DSL.

Summary

Public properties

Int

Sets the capture mode for this use case.

Int

Sets the flash mode for this use case.

Executor

Sets the background executor for I/O tasks.

Boolean

Sets whether postview is enabled for this use case.

Int

Sets the JPEG quality for this use case.

Int

Sets the output format for this use case.

ResolutionSelector

Sets the resolution selector for postview images.

ResolutionSelector

Sets the resolution selector for this use case.

ImageCapture.ScreenFlash

Sets the ScreenFlash implementation for this use case.

String

Sets the target name for this use case configuration.

Int

Sets the target rotation for this use case.

Extension functions

inline Unit

Applies Camera2 options inside an ImageCaptureScope DSL block.

Public properties

captureMode

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var captureModeInt

Sets the capture mode for this use case.

See also
setCaptureMode

flashMode

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var flashModeInt

Sets the flash mode for this use case.

See also
setFlashMode

ioExecutor

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var ioExecutorExecutor

Sets the background executor for I/O tasks.

See also
setIoExecutor

isPostviewEnabled

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var isPostviewEnabledBoolean

Sets whether postview is enabled for this use case.

jpegQuality

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var jpegQualityInt

Sets the JPEG quality for this use case.

See also
setJpegQuality

outputFormat

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var outputFormatInt

Sets the output format for this use case.

See also
setOutputFormat

postviewResolutionSelector

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var postviewResolutionSelectorResolutionSelector

Sets the resolution selector for postview images.

resolutionSelector

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var resolutionSelectorResolutionSelector

Sets the resolution selector for this use case.

screenFlash

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var screenFlashImageCapture.ScreenFlash

Sets the ScreenFlash implementation for this use case.

See also
setScreenFlash

targetName

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var targetNameString

Sets the target name for this use case configuration.

See also
setTargetName

targetRotation

Added in 1.7.0-alpha03
Deprecated in 1.7.0-alpha03
var targetRotationInt

Sets the target rotation for this use case.

Extension functions

ImageCaptureScope.camera2Interop

inline fun ImageCaptureScope.camera2Interop(crossinline block: ImageCaptureCamera2Interop.() -> Unit): Unit

Applies Camera2 options inside an ImageCaptureScope DSL block.

Configures Camera2 options on the underlying ImageCapture.Builder within an imageCapture { ... } DSL block.

Options configured via ImageCaptureCamera2Interop include:

Note: Using Camera2 interop options can override internal CameraX configurations. The capture request keys for one-shot still captures (such as androidx.camera.core.ImageCapture.takePicture) are determined by copying all repeating request keys (which may include keys added via androidx.camera.core.SessionConfig.Builder.setInterop or androidx.camera.core.CameraControl.applyInteropAsync) and then overriding them with the still capture request keys configured here. If an option configured via interop conflicts with options required by CameraX internally, the option from Camera2Interop will override, which may result in unexpected behavior.

Warning: Callbacks configured via interop receive raw android.hardware.camera2.CameraCaptureSession instances. Directly invoking state-altering methods on these raw objects (such as android.hardware.camera2.CameraCaptureSession.close or android.hardware.camera2.CameraCaptureSession.abortCaptures) bypasses CameraX pipeline management and may cause state desynchronization, stream interruption, or application crashes.

import androidx.camera.camera2.interop.camera2Interop
import androidx.camera.core.imageCapture

val imageCapture = imageCapture {
    camera2Interop {
        stillCaptureRequestTemplateType = CameraDevice.TEMPLATE_PREVIEW
        stillCaptureRequest[CaptureRequest.CONTROL_AF_MODE] = CaptureRequest.CONTROL_AF_MODE_OFF
        stillCaptureCallback =
            object : CameraCaptureSession.CaptureCallback() {
                override fun onCaptureCompleted(
                    session: CameraCaptureSession,
                    request: CaptureRequest,
                    result: TotalCaptureResult,
                ) {}
            }
        physicalCameraId = "5"
    }
}
Parameters
crossinline block: ImageCaptureCamera2Interop.() -> Unit

configuration block setting Camera2 options on ImageCaptureCamera2Interop