SurfaceOrientedMeteringPointFactory

@RequiresApi(value = 21)
public class SurfaceOrientedMeteringPointFactory extends MeteringPointFactory


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.

See also
MeteringPoint

Summary

Public constructors

SurfaceOrientedMeteringPointFactory(float width, float height)

Creates the SurfaceOrientedMeteringPointFactory by width and height

SurfaceOrientedMeteringPointFactory(
    float width,
    float height,
    @NonNull UseCase useCaseForAspectRatio
)

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

Inherited methods

From androidx.camera.core.MeteringPointFactory
final @NonNull MeteringPoint
createPoint(float x, float y)

Creates a MeteringPoint by x, y.

final @NonNull MeteringPoint
createPoint(float x, float y, float size)

Creates a MeteringPoint by x, y, size.

static float

Returns default point size.

Public constructors

SurfaceOrientedMeteringPointFactory

Added in 1.0.0
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 an area (0, 0) - (width, height) within which apps can specify metering points by createPoint. 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
float width

the width of the area in surface orientation.

float height

the height of the area in surface orientation.

SurfaceOrientedMeteringPointFactory

Added in 1.0.0
public SurfaceOrientedMeteringPointFactory(
    float width,
    float height,
    @NonNull UseCase useCaseForAspectRatio
)

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. 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
float width

the width of the area in surface orientation.

float height

the height of the area in surface orientation.

@NonNull UseCase useCaseForAspectRatio

the UseCase to get the surface aspect ratio.