DisplayOrientedMeteringPointFactory

public final class DisplayOrientedMeteringPointFactory
extends MeteringPointFactory

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


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:

Summary

Public constructors

DisplayOrientedMeteringPointFactory(Context context, CameraSelector cameraSelector, float width, float height)

Creates a DisplayOrientedMeteringPointFactory for converting View (x, y) into a MeteringPoint based on default display's orientation and CameraSelector.

DisplayOrientedMeteringPointFactory(Display display, CameraSelector cameraSelector, float width, float height)

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

Inherited methods

Public constructors

DisplayOrientedMeteringPointFactory

public DisplayOrientedMeteringPointFactory (Context context, 
                CameraSelector cameraSelector, 
                float width, 
                float height)

Creates a DisplayOrientedMeteringPointFactory for converting View (x, y) into a MeteringPoint based on default display's orientation and CameraSelector.

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 default 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 MeteringPointFactory.createPoint(float, float) should be adjusted to this coordinate system first.

Parameters
context Context: context to get the WindowManager for default display rotation.

cameraSelector CameraSelector: current cameraSelector to choose camera.

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

height float: the height of the coordinate which are mapped to the full camera preview FOVin default display's orientation.

DisplayOrientedMeteringPointFactory

public DisplayOrientedMeteringPointFactory (Display display, 
                CameraSelector cameraSelector, 
                float width, 
                float height)

Creates a DisplayOrientedMeteringPointFactory for converting View (x, y) into a MeteringPoint based on custom display's rotation and CameraSelector. This is used in multi-display situation.

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 default 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 MeteringPointFactory.createPoint(float, float) should be adjusted to this coordinate system first.

Parameters
display Display: Display to get the orientation from.

cameraSelector CameraSelector: current cameraSelector to choose camera.

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

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