ImageCaptureScope


@CameraXDsl
class ImageCaptureScope


Scope class for ImageCapture configuration DSL.

Summary

Public properties

Int

Sets or gets the capture mode for this use case.

Int

Sets or gets the flash mode for this use case.

Executor

Sets or gets the background executor for I/O tasks.

Boolean

Sets or gets whether postview is enabled for this use case.

Int

Sets or gets the JPEG quality for this use case.

Int

Sets or gets the output format for this use case.

ResolutionSelector

Sets or gets the resolution selector for postview images.

ResolutionSelector

Sets or gets the resolution selector for this use case.

ImageCapture.ScreenFlash?

Sets or gets the ScreenFlash implementation for this use case.

String

Sets or gets the target name for this use case configuration.

Int

Sets or gets 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-rc01
var captureMode: Int

Sets or gets the capture mode for this use case.

See also
setCaptureMode

flashMode

Added in 1.7.0-rc01
var flashMode: Int

Sets or gets the flash mode for this use case.

See also
setFlashMode

ioExecutor

Added in 1.7.0-rc01
var ioExecutor: Executor

Sets or gets the background executor for I/O tasks.

See also
setIoExecutor

isPostviewEnabled

Added in 1.7.0-rc01
var isPostviewEnabled: Boolean

Sets or gets whether postview is enabled for this use case.

jpegQuality

Added in 1.7.0-rc01
var jpegQuality: Int

Sets or gets the JPEG quality for this use case.

See also
setJpegQuality

outputFormat

Added in 1.7.0-rc01
var outputFormat: Int

Sets or gets the output format for this use case.

See also
setOutputFormat

postviewResolutionSelector

Added in 1.7.0-rc01
var postviewResolutionSelector: ResolutionSelector

Sets or gets the resolution selector for postview images.

resolutionSelector

Added in 1.7.0-rc01
var resolutionSelector: ResolutionSelector

Sets or gets the resolution selector for this use case.

screenFlash

Added in 1.7.0-rc01
var screenFlash: ImageCapture.ScreenFlash?

Sets or gets the ScreenFlash implementation for this use case.

Note: Setting this property to null is a no-op on the underlying ImageCapture.Builder because ImageCapture.Builder.setScreenFlash requires a non-null ImageCapture.ScreenFlash.

See also
setScreenFlash

targetName

Added in 1.7.0-rc01
var targetName: String

Sets or gets the target name for this use case configuration.

See also
setTargetName

targetRotation

Added in 1.7.0-rc01
var targetRotation: Int

Sets or gets 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, lifecycle, or request-submitting methods on these raw objects bypasses CameraX pipeline management and causes state desynchronization, stream freezing, or crashes. Do not invoke:

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