ViewPort

public final class ViewPort
extends Object

java.lang.Object
   ↳ androidx.camera.core.ViewPort


The field of view of one or many UseCases.

The ViewPort defines a FOV which is used by CameraX to calculate output crop rects. For use cases associated with the same ViewPort in a UseCaseGroup, the output crop rect will be mapped to the same camera sensor area. Usually ViewPort is configured to optimize for Preview so that ImageAnalysis and ImageCapture produce the same crop rect in a WYSIWYG way.

If the ViewPort is used with a ImageCapture and ImageCapture.takePicture(ImageCapture.OutputFileOptions, Executor, ImageCapture.OnImageSavedCallback) is called, the image may be cropped before saving to disk which introduces an additional latency. To avoid the latency and get the uncropped image, please use the in-memory method ImageCapture.takePicture(Executor, ImageCapture.OnImageCapturedCallback).

For ImageAnalysis and in-memory ImageCapture, the output crop rect is ImageProxy.getCropRect(); for on-disk ImageCapture, the image is cropped before saving; for Preview, the crop rect is SurfaceRequest.TransformationInfo.getCropRect(). Caller should transform the output in a way that only the area defined by the crop rect is visible to end users. Once the crop rect is applied, all the use cases will produce the same image with possibly different resolutions.

Summary

Nested classes

class ViewPort.Builder

Builder for ViewPort

Constants

int FILL_CENTER

Generate a crop rect that once applied, it scales the output while maintaining its aspect ratio, so it fills the entire ViewPort and center it.

int FILL_END

Generate a crop rect that once applied, it scales the output while maintaining its aspect ratio, so it fills the entire ViewPort, and align it to the end of the ViewPort, which is the bottom right corner in a left-to-right (LTR) layout, or the bottom left corner in a right-to-left (RTL) layout.

int FILL_START

Generate a crop rect that once applied, it scales the output while maintaining its aspect ratio, so it fills the entire ViewPort, and align it to the start of the ViewPort, which is the top left corner in a left-to-right (LTR) layout, or the top right corner in a right-to-left (RTL) layout.

int FIT

Generate the max possible crop rect ignoring the aspect ratio.

Public methods

Rational