PreviewConfig.Builder
public
static
final
class
PreviewConfig.Builder
extends Object
implements
Config.ExtendableBuilder,
Builder<PreviewConfig.Builder>
java.lang.Object | |
↳ | androidx.camera.core.PreviewConfig.Builder |
Builder for a PreviewConfig
.
Summary
Public constructors | |
---|---|
PreviewConfig.Builder()
Creates a new Builder object. |
Public methods | |
---|---|
PreviewConfig
|
build()
Builds an immutable |
static
PreviewConfig.Builder
|
fromConfig(PreviewConfig configuration)
Generates a Builder from another Config object |
PreviewConfig.Builder
|
setBackgroundExecutor(Executor executor)
Sets the default executor that will be used for background tasks. |
PreviewConfig.Builder
|
setLensFacing(CameraX.LensFacing lensFacing)
Sets the primary camera to be configured based on the direction the lens is facing. |
PreviewConfig.Builder
|
setTargetAspectRatio(AspectRatio aspectRatio)
Sets the aspect ratio of the intended target for images from this configuration. |
PreviewConfig.Builder
|
setTargetName(String targetName)
Sets the name of the target object being configured. |
PreviewConfig.Builder
|
setTargetResolution(Size resolution)
Sets the resolution of the intended target from this configuration. |
PreviewConfig.Builder
|
setTargetRotation(int rotation)
Sets the rotation of the intended target for images from this configuration. |
Inherited methods | |
---|---|
Public constructors
PreviewConfig.Builder
public PreviewConfig.Builder ()
Creates a new Builder object.
Public methods
build
public PreviewConfig build ()
Builds an immutable PreviewConfig
from the current state.
Returns | |
---|---|
PreviewConfig |
A PreviewConfig populated with the current state.
|
fromConfig
public static PreviewConfig.Builder fromConfig (PreviewConfig configuration)
Generates a Builder from another Config object
Parameters | |
---|---|
configuration |
PreviewConfig : An immutable configuration to pre-populate this builder. |
Returns | |
---|---|
PreviewConfig.Builder |
The new Builder. |
setBackgroundExecutor
public PreviewConfig.Builder setBackgroundExecutor (Executor executor)
Sets the default executor that will be used for background tasks.
Parameters | |
---|---|
executor |
Executor : The executor which will be used for background tasks. |
Returns | |
---|---|
PreviewConfig.Builder |
the current Builder. |
setLensFacing
public PreviewConfig.Builder setLensFacing (CameraX.LensFacing lensFacing)
Sets the primary camera to be configured based on the direction the lens is facing.
If multiple cameras exist with equivalent lens facing direction, the first ("primary") camera for that direction will be chosen.
Parameters | |
---|---|
lensFacing |
CameraX.LensFacing : The direction of the camera's lens. |
Returns | |
---|---|
PreviewConfig.Builder |
the current Builder. |
setTargetAspectRatio
public PreviewConfig.Builder setTargetAspectRatio (AspectRatio aspectRatio)
Sets the aspect ratio of the intended target for images from this configuration.
It is not allowed to set both target aspect ratio and target resolution on the same use case.
The target aspect ratio is used as a hint when determining the resulting output aspect ratio which may differ from the request, possibly due to device constraints. Application code should check the resulting output's resolution.
For Preview, the output is the SurfaceTexture of the
Preview.PreviewOutput
.
Parameters | |
---|---|
aspectRatio |
AspectRatio : A AspectRatio representing the ratio of the
target's width and height. |
Returns | |
---|---|
PreviewConfig.Builder |
The current Builder. |
setTargetName
public PreviewConfig.Builder setTargetName (String targetName)
Sets the name of the target object being configured.
The name should be a value that can uniquely identify an instance of the object being configured.
Parameters | |
---|---|
targetName |
String : A unique string identifier for the instance of the class being
configured. |
Returns | |
---|---|
PreviewConfig.Builder |
the current Builder. |
setTargetResolution
public PreviewConfig.Builder setTargetResolution (Size resolution)
Sets the resolution of the intended target from this configuration.
The target resolution attempts to establish a minimum bound for the preview resolution. The actual preview resolution will be the closest available resolution in size that is not smaller than the target resolution, as determined by the Camera implementation. However, if no resolution exists that is equal to or larger than the target resolution, the nearest available resolution smaller than the target resolution will be chosen.
It is not allowed to set both target aspect ratio and target resolution on the same use case.
The target aspect ratio will also be set the same as the aspect ratio of the provided
Size
. Make sure to set the target resolution with the correct orientation.
Parameters | |
---|---|
resolution |
Size : The target resolution to choose from supported output sizes list. |
Returns | |
---|---|
PreviewConfig.Builder |
The current Builder. |
setTargetRotation
public PreviewConfig.Builder setTargetRotation (int rotation)
Sets the rotation of the intended target for images from this configuration.
This is one of four valid values: Surface.ROTATION_0
, Surface.ROTATION_90
, Surface.ROTATION_180
, Surface.ROTATION_270
.
Rotation values are relative to the "natural" rotation, Surface.ROTATION_0
.
Parameters | |
---|---|
rotation |
int : The rotation of the intended target. |
Returns | |
---|---|
PreviewConfig.Builder |
The current Builder. |