public final class

ViewPort.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.ViewPort.Builder

Overview

Builder for ViewPort.

Summary

Constructors
publicBuilder(Rational aspectRatio, int rotation)

Creates ViewPort.Builder with aspect ratio and rotation.

Methods
public ViewPortbuild()

Builds the ViewPort.

public ViewPort.BuildersetLayoutDirection(int layoutDirection)

Sets the layout direction of the ViewPort.

public ViewPort.BuildersetScaleType(int scaleType)

Sets the scale type of the ViewPort.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(Rational aspectRatio, int rotation)

Creates ViewPort.Builder with aspect ratio and rotation.

To create a ViewPort that is based on the Preview use case, the aspect ratio should be the dimension of the View and the rotation should be the value of Preview.getTargetRotation():

 val aspectRatio = Rational(viewFinder.width, viewFinder.height)
 val viewport = ViewPort.Builder(aspectRatio, preview.getTargetRotation()).build()
 

In a scenario where Preview is not used, for example, face detection in ImageAnalysis and taking pictures with ImageCapture when faces are found, the ViewPort should be created with the aspect ratio and rotation of the ImageCapture use case.

Parameters:

aspectRatio: aspect ratio of the output crop rect if the scale type is FILL_START, FILL_CENTER or FILL_END. This is usually the width/height of the preview viewfinder that displays the camera feed. The value is ignored if the scale type is FIT.
rotation: The rotation value is one of four valid values: , , , .

Methods

public ViewPort.Builder setScaleType(int scaleType)

Sets the scale type of the ViewPort.

The value is used by UseCase to calculate the crop rect.

The default value is ViewPort.FILL_CENTER if not set.

public ViewPort.Builder setLayoutDirection(int layoutDirection)

Sets the layout direction of the ViewPort.

The layout direction decides the start and the end of the crop rect if the scale type is ViewPort.FILL_END or ViewPort.FILL_START.

The default value is if not set.

public ViewPort build()

Builds the ViewPort.