SurfaceOrientedMeteringPointFactory

public class SurfaceOrientedMeteringPointFactory
extends MeteringPointFactory

java.lang.Object
   ↳ androidx.camera.core.MeteringPointFactory
     ↳ androidx.camera.core.SurfaceOrientedMeteringPointFactory


A MeteringPointFactory that can create MeteringPoint by surface oriented x, y on a 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.

See also:

Summary

Public constructors

SurfaceOrientedMeteringPointFactory(float width, float height)

Creates the SurfaceOrientedMeteringPointFactory by width and height

The width/height is the width/height in surface orientation which defines a area (0, 0) - (width, height) where apps can pick a point (x, y) to MeteringPointFactory.createPoint(float, float).

SurfaceOrientedMeteringPointFactory(float width, float height, UseCase useCaseForSurface)

Creates the SurfaceOrientedMeteringPointFactory by width, height and useCaseForAspectRatio.

Inherited methods

Public constructors

SurfaceOrientedMeteringPointFactory

public SurfaceOrientedMeteringPointFactory (float width, 
                float height)

Creates the SurfaceOrientedMeteringPointFactory by width and height

The width/height is the width/height in surface orientation which defines a area (0, 0) - (width, height) where apps can pick a point (x, y) to MeteringPointFactory.createPoint(float, float). User can set the width and height to 1.0 to make the (x, y) be normalized coordinates [0..1].

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.

SurfaceOrientedMeteringPointFactory

public SurfaceOrientedMeteringPointFactory (float width, 
                float height, 
                UseCase useCaseForSurface)

Creates the SurfaceOrientedMeteringPointFactory by width, height and useCaseForAspectRatio.

The width/height is the width/height in surface orientation which defines a area (0, 0) - (width, height) where apps can pick a point (x, y) to MeteringPointFactory.createPoint(float, float). User can set the width and height to 1.0 to make the (x, y) be normalized coordinates [0..1].

useCaseForSurface is used to determine the surface aspect ratio for for final coordinates conversion. This useCaseForSurface needs to be bound via CameraX #bindToLifecycle(LifecycleOwner, CameraSelector, UseCase...) first. Otherwise it will throw aIllegalStateException.

Parameters
width float: the width of the area in surface orientation.

height float: the height of the area in surface orientation.

useCaseForSurface UseCase: the UseCase to get the surface aspect ratio.