# SurfaceOrientedMeteringPointFactory

Artifact: [androidx.camera:camera-core](https://developer.android.com/jetpack/androidx/releases/camera) [View Source](https://cs.android.com/search?q=file:androidx/camera/core/SurfaceOrientedMeteringPointFactory.java+class:androidx.camera.core.SurfaceOrientedMeteringPointFactory) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

*** ** * ** ***


```
public class SurfaceOrientedMeteringPointFactory extends MeteringPointFactory
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.camera.core.MeteringPointFactory](https://developer.android.com/reference/androidx/camera/core/MeteringPointFactory) ||
|   | ↳ | [androidx.camera.core.SurfaceOrientedMeteringPointFactory](https://developer.android.com/reference/androidx/camera/core/SurfaceOrientedMeteringPointFactory) |

*** ** * ** ***

A `https://developer.android.com/reference/androidx/camera/core/MeteringPointFactory` that can create `https://developer.android.com/reference/androidx/camera/core/MeteringPoint` by surface oriented x, y on an area defined by (0, 0) - (width, height). `https://developer.android.com/reference/androidx/camera/core/MeteringPoint` can then be used to construct a `https://developer.android.com/reference/androidx/camera/core/FocusMeteringAction` to start a focus and metering action.

The `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/android/view/Surface.html` of certain aspect ratio. `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/androidx/camera/core/ImageAnalysis`. Apps can pass the `https://developer.android.com/reference/androidx/camera/core/ImageAnalysis` instance for useCaseForSurface argument and CameraX will then adjust the final sensor coordinates by aspect ratio of ImageAnalysis.

| See also |
|---|---|
| `https://developer.android.com/reference/androidx/camera/core/MeteringPoint` |   |

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/camera/core/SurfaceOrientedMeteringPointFactory#SurfaceOrientedMeteringPointFactory(float,float)(float width, float height)` Creates the `https://developer.android.com/reference/androidx/camera/core/SurfaceOrientedMeteringPointFactory` by width and height |
| `https://developer.android.com/reference/androidx/camera/core/SurfaceOrientedMeteringPointFactory#SurfaceOrientedMeteringPointFactory(float,float,androidx.camera.core.UseCase)( float width, float height, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/UseCase useCaseForAspectRatio )` Creates the `https://developer.android.com/reference/androidx/camera/core/SurfaceOrientedMeteringPointFactory` by width, height and the surface aspect ratio. |

| ### Inherited methods |
|---|
| From [androidx.camera.core.MeteringPointFactory](https://developer.android.com/reference/androidx/camera/core/MeteringPointFactory) |---|---| | `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/MeteringPoint` | `https://developer.android.com/reference/androidx/camera/core/MeteringPointFactory#createPoint(float,float)(float x, float y)` Creates a `https://developer.android.com/reference/androidx/camera/core/MeteringPoint` by x, y. | | `final @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/MeteringPoint` | `https://developer.android.com/reference/androidx/camera/core/MeteringPointFactory#createPoint(float,float,float)(float x, float y, float size)` Creates a `https://developer.android.com/reference/androidx/camera/core/MeteringPoint` by x, y, size. | | `static float` | `https://developer.android.com/reference/androidx/camera/core/MeteringPointFactory#getDefaultPointSize()()` Returns default point size. | |

## Public constructors

### SurfaceOrientedMeteringPointFactory

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

```
public SurfaceOrientedMeteringPointFactory(float width, float height)
```

Creates the `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/androidx/camera/core/MeteringPointFactory#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 `https://developer.android.com/reference/androidx/camera/core/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](https://developer.android.com/jetpack/androidx/releases/camera#1.0.0)

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

Creates the `https://developer.android.com/reference/androidx/camera/core/SurfaceOrientedMeteringPointFactory` by width, height and the surface aspect ratio. The surface aspect ratio is retrieved from the `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/androidx/camera/core/MeteringPointFactory#createPoint(float,float)`. Setting width and height to 1.0 will allow points to be created by specifying normalized coordinates.

A `https://developer.android.com/reference/androidx/camera/core/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 `https://developer.android.com/reference/java/lang/IllegalStateException.html` will be thrown.

| Parameters |
|---|---|
| `float width` | the width of the area in surface orientation. |
| `float height` | the height of the area in surface orientation. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/camera/core/UseCase useCaseForAspectRatio` | the `https://developer.android.com/reference/androidx/camera/core/UseCase` to get the surface aspect ratio. |