DisplayOrientedMeteringPointFactory


public final class DisplayOrientedMeteringPointFactory extends MeteringPointFactory


A MeteringPointFactory that can convert a View (x, y) into a MeteringPoint which can then be used to construct a FocusMeteringAction to start a focus and metering action.

For apps showing full camera preview in a View without any scaling, cropping or rotating applied, they can simply use view width and height to create the DisplayOrientedMeteringPointFactory and then pass View (x, y) to create a MeteringPoint. This factory will convert the (x, y) into the sensor (x, y) based on display rotation and lensFacing.

If camera preview is scaled, cropped or rotated in the View, it is applications' duty to transform the coordinates properly so that the width and height of this factory represents the full Preview FOV and also the (x,y) passed to create MeteringPoint needs to be adjusted by apps to the coordinates left-top (0,0) - right-bottom (width, height). For example, if the preview is scaled to 2X from the center and is cropped in a View. Assuming that the dimension of View is (240, 320), then the width/height of this DisplayOrientedMeteringPointFactory should be (480, 640). And the (x, y) from the View should be converted to (x + (480-240)/2, y + (640 - 320)/2) first.

See also
MeteringPoint

Summary

Public constructors

DisplayOrientedMeteringPointFactory(
    @NonNull Display display,
    @NonNull CameraInfo cameraInfo,
    float width,
    float height
)

Creates a DisplayOrientedMeteringPointFactory for converting View (x, y) into a MeteringPoint based on the current display's rotation and CameraInfo.

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

DisplayOrientedMeteringPointFactory

Added in 1.0.0
public DisplayOrientedMeteringPointFactory(
    @NonNull Display display,
    @NonNull CameraInfo cameraInfo,
    float width,
    float height
)

Creates a DisplayOrientedMeteringPointFactory for converting View (x, y) into a MeteringPoint based on the current display's rotation and CameraInfo.

The width/height of this factory forms a coordinate left-top (0, 0) - right-bottom (width, height) which represents the full camera preview FOV in the display's orientation. For apps showing full camera preview in a View, it is as simple as passing View's width/height and passing View (x, y) directly to create a MeteringPoint. Otherwise the (x, y) passed to createPoint should be adjusted to this coordinate system first.

Parameters
@NonNull Display display

Display to get the orientation from. This should be the current display where camera preview is showing.

@NonNull CameraInfo cameraInfo

the information for the Camera to generate the metering point for

float width

the width of the coordinate which are mapped to the full camera preview FOV in given display's orientation.

float height

the height of the coordinate which are mapped to the full camera preview FOV in given display's orientation.