Google is committed to advancing racial equity for Black communities. See how.


class Builder

Builder for ViewPort.


Public constructors
<init>(@NonNull aspectRatio: Rational, rotation: Int)

Creates ViewPort.Builder with aspect ratio and rotation.

Public methods

Builds the ViewPort.

Public constructors


    @NonNull aspectRatio: Rational,
    rotation: Int)

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():

<code>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.

aspectRatio Rational: 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 Int: The rotation value is one of four valid values: Surface#ROTATION_0, Surface#ROTATION_90, Surface#ROTATION_180, Surface#ROTATION_270.

Public methods


@NonNull fun build(): ViewPort

Builds the ViewPort.