SurfaceOrientedMeteringPointFactory

open class SurfaceOrientedMeteringPointFactory : MeteringPointFactory
kotlin.Any
   ↳ androidx.camera.core.MeteringPointFactory
   ↳ androidx.camera.core.SurfaceOrientedMeteringPointFactory

A MeteringPointFactory that can create MeteringPoint by surface oriented x, y on an area defined by (0, 0) - (width, height). MeteringPoint can then be used to construct a FocusMeteringAction to start a focus and metering action.

The MeteringPoint defines a normalized coordinate system whose left-top is (0, 0) and right-bottom is (1.0, 1.0). This coordinate system is the normalized coordinate system of a Surface of certain aspect ratio. SurfaceOrientedMeteringPointFactory is the simplest factory to create this normalized (x, y) by dividing the (x, y) with (width, height).

This factory is suitable for apps that already have coordinates converted into surface oriented coordinates. It is also useful for apps that want to focus on something detected in ImageAnalysis. Apps can pass the ImageAnalysis instance for useCaseForSurface argument and CameraX will then adjust the final sensor coordinates by aspect ratio of ImageAnalysis.

Summary

Public constructors
<init>(width: Float, height: Float)

Creates the SurfaceOrientedMeteringPointFactory by width and height

<init>(width: Float, height: Float, @NonNull useCaseForAspectRatio: UseCase)

Creates the SurfaceOrientedMeteringPointFactory by width, height and the surface aspect ratio.

Inherited functions

Public constructors

<init>

SurfaceOrientedMeteringPointFactory(
    width: Float,
    height: Float)

Creates the SurfaceOrientedMeteringPointFactory by width and height

The width/height is the width/height in surface orientation which defines an area (0, 0) - (width, height) within which apps can specify metering points by createPoint(float, float). Setting width and height to 1.0 will allow points to be created by specifying normalized coordinates.

By default, it will use active Preview to get the surface aspect ratio for final coordinates conversion.

Parameters
width Float: the width of the area in surface orientation.
height Float: the height of the area in surface orientation.

<init>

SurfaceOrientedMeteringPointFactory(
    width: Float,
    height: Float,
    @NonNull useCaseForAspectRatio: UseCase)

Creates the SurfaceOrientedMeteringPointFactory by width, height and the surface aspect ratio. The surface aspect ratio is retrieved from the UseCase.

The width/height is the width/height in surface orientation which defines an area (0, 0) - (width, height) within which apps can specify metering points by createPoint(float, float). Setting width and height to 1.0 will allow points to be created by specifying normalized coordinates.

A UseCase is passed in order to determine the surface aspect ratio for final coordinates conversion. This use case needs to be bound at the time this method is called, otherwise an IllegalStateException will be thrown.

Parameters
width Float: the width of the area in surface orientation.
height Float: the height of the area in surface orientation.
useCaseForAspectRatio UseCase: the UseCase to get the surface aspect ratio.