SurfaceRequest.TransformationInfo

public static abstract class SurfaceRequest.TransformationInfo
extends Object

java.lang.Object
   ↳ androidx.camera.core.SurfaceRequest.TransformationInfo


Transformation associated the preview output.

The SurfaceRequest.TransformationInfo can be used transform the Surface provided via SurfaceRequest.provideSurface(Surface, Executor, Consumer). The info is based on the camera sensor rotation, preview target rotation and the ViewPort associated with the Preview. The application of the info depends on the source of the Surface. For detailed example, please check out the source code of PreviewView in androidx.camera.view artifact.

The info is also needed to transform coordinates across use cases. In a face detection example, one common scenario is running a face detection algorithm against a ImageAnalysis use case, and highlight the detected face in the preview. Below is a code sample to get the transformation Matrix based on the ImageProxy from ImageAnalysis and the SurfaceRequest.TransformationInfo from Preview:


     // Get rotation transformation.
     val transformation = Matrix()
     transformation.setRotate(info.getRotationDegrees())

     // Get rotated crop rect and cropping transformation.
     val rotatedRect = new RectF()
     rotation.mapRect(rotatedRect, RectF(imageProxy.getCropRect()))
     rotatedRect.sort()
     val cropTransformation = Matrix()
     cropTransformation.setRectToRect(
          RectF(imageProxy.getCropRect()), rotatedRect, ScaleToFit.FILL)

     // Concatenate the rotation and cropping transformations.
     transformation.postConcat(cropTransformation)
 

Summary

Public methods

abstract Rect getCropRect()

Returns the crop rect rectangle.

abstract int getRotationDegrees()

Returns the rotation needed to transform the output from sensor to the target rotation.

Inherited methods