ImageCaptureScope


@CameraXDsl
public final class ImageCaptureScope


Scope class for ImageCapture configuration DSL.

Summary

Public methods

final int

Sets or gets the capture mode for this use case.

final int

Sets or gets the flash mode for this use case.

final @NonNull Executor

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

final @IntRange(from = 1, to = 100) int

Sets or gets the JPEG quality for this use case.

final int

Sets or gets the output format for this use case.

final @NonNull ResolutionSelector

Sets or gets the resolution selector for postview images.

final @NonNull ResolutionSelector

Sets or gets the resolution selector for this use case.

final @Nullable ImageCapture.ScreenFlash

Sets or gets the ScreenFlash implementation for this use case.

final @NonNull String

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

final int

Sets or gets the target rotation for this use case.

final boolean

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

final void
setCaptureMode(int value)

Sets or gets the capture mode for this use case.

final void
setFlashMode(int value)

Sets or gets the flash mode for this use case.

final void

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

final void
setJpegQuality(@IntRange(from = 1, to = 100) int value)

Sets or gets the JPEG quality for this use case.

final void
setOutputFormat(int value)

Sets or gets the output format for this use case.

final void
setPostviewEnabled(boolean value)

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

final void

Sets or gets the resolution selector for postview images.

final void

Sets or gets the resolution selector for this use case.

final void

Sets or gets the ScreenFlash implementation for this use case.

final void

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

final void
setTargetRotation(int value)

Sets or gets the target rotation for this use case.

Extension functions

final void

Applies Camera2 options inside an ImageCaptureScope DSL block.

Public methods

getCaptureMode

Added in 1.7.0-rc01
public final int getCaptureMode()

Sets or gets the capture mode for this use case.

See also
setCaptureMode

getFlashMode

Added in 1.7.0-rc01
public final int getFlashMode()

Sets or gets the flash mode for this use case.

See also
setFlashMode

getIoExecutor

Added in 1.7.0-rc01
public final @NonNull Executor getIoExecutor()

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

See also
setIoExecutor

getJpegQuality

Added in 1.7.0-rc01
public final @IntRange(from = 1, to = 100) int getJpegQuality()

Sets or gets the JPEG quality for this use case.

See also
setJpegQuality

getOutputFormat

Added in 1.7.0-rc01
public final int getOutputFormat()

Sets or gets the output format for this use case.

See also
setOutputFormat

getPostviewResolutionSelector

Added in 1.7.0-rc01
public final @NonNull ResolutionSelector getPostviewResolutionSelector()

Sets or gets the resolution selector for postview images.

getResolutionSelector

Added in 1.7.0-rc01
public final @NonNull ResolutionSelector getResolutionSelector()

Sets or gets the resolution selector for this use case.

getScreenFlash

Added in 1.7.0-rc01
public final @Nullable ImageCapture.ScreenFlash getScreenFlash()

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

getTargetName

Added in 1.7.0-rc01
public final @NonNull String getTargetName()

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

See also
setTargetName

getTargetRotation

Added in 1.7.0-rc01
public final int getTargetRotation()

Sets or gets the target rotation for this use case.

isPostviewEnabled

Added in 1.7.0-rc01
public final boolean isPostviewEnabled()

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

setCaptureMode

Added in 1.7.0-rc01
public final void setCaptureMode(int value)

Sets or gets the capture mode for this use case.

See also
setCaptureMode

setFlashMode

Added in 1.7.0-rc01
public final void setFlashMode(int value)

Sets or gets the flash mode for this use case.

See also
setFlashMode

setIoExecutor

Added in 1.7.0-rc01
public final void setIoExecutor(@NonNull Executor value)

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

See also
setIoExecutor

setJpegQuality

Added in 1.7.0-rc01
public final void setJpegQuality(@IntRange(from = 1, to = 100) int value)

Sets or gets the JPEG quality for this use case.

See also
setJpegQuality

setOutputFormat

Added in 1.7.0-rc01
public final void setOutputFormat(int value)

Sets or gets the output format for this use case.

See also
setOutputFormat

setPostviewEnabled

Added in 1.7.0-rc01
public final void setPostviewEnabled(boolean value)

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

setPostviewResolutionSelector

Added in 1.7.0-rc01
public final void setPostviewResolutionSelector(@NonNull ResolutionSelector value)

Sets or gets the resolution selector for postview images.

setResolutionSelector

Added in 1.7.0-rc01
public final void setResolutionSelector(@NonNull ResolutionSelector value)

Sets or gets the resolution selector for this use case.

setScreenFlash

Added in 1.7.0-rc01
public final void setScreenFlash(ImageCapture.ScreenFlash value)

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

setTargetName

Added in 1.7.0-rc01
public final void setTargetName(@NonNull String value)

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

See also
setTargetName

setTargetRotation

Added in 1.7.0-rc01
public final void setTargetRotation(int value)

Sets or gets the target rotation for this use case.

Extension functions

Camera2InteropEx.camera2Interop

public final void Camera2InteropEx.camera2Interop(
    @NonNull ImageCaptureScope receiver,
    @NonNull Function1<@NonNull ImageCaptureCamera2Interop, Unit> block
)

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
@NonNull Function1<@NonNull ImageCaptureCamera2Interop, Unit> block

configuration block setting Camera2 options on ImageCaptureCamera2Interop