# CoordinateTransform

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

*** ** * ** ***

<br />

```
class CoordinateTransform
```

<br />

*** ** * ** ***

This class represents the transform from one `https://developer.android.com/reference/kotlin/androidx/camera/view/transform/OutputTransform` to another.

This class can be used to map the coordinates of one `https://developer.android.com/reference/kotlin/androidx/camera/view/transform/OutputTransform` to another, given that they are associated with the same `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort`. `https://developer.android.com/reference/kotlin/androidx/camera/view/transform/OutputTransform` can represent the output of a `https://developer.android.com/reference/kotlin/androidx/camera/core/UseCase` or `https://developer.android.com/reference/kotlin/androidx/camera/view/PreviewView`. For example, mapping the coordinates of detected objects from `https://developer.android.com/reference/kotlin/androidx/camera/core/ImageAnalysis` output to the drawing location in `https://developer.android.com/reference/kotlin/androidx/camera/view/PreviewView`.

```kotlin
// imageProxy the output of an ImageAnalysis.
OutputTransform source = ImageProxyTransformFactory().getOutputTransform(imageProxy);
OutputTransform target = previewView.getOutputTransform();

// Build the transform from ImageAnalysis to PreviewView
CoordinateTransform coordinateTransform = new CoordinateTransform(source, target);

// Detect face in ImageProxy and transform the coordinates to PreviewView.
// The value of faceBox can be used to highlight the face in PreviewView.
RectF faceBox = detectFaceInImageProxy(imageProxy);
coordinateTransform.mapRect(faceBox);
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/camera/view/transform/CoordinateTransform#CoordinateTransform(androidx.camera.view.transform.OutputTransform,androidx.camera.view.transform.OutputTransform)(source: https://developer.android.com/reference/kotlin/androidx/camera/view/transform/OutputTransform, target: https://developer.android.com/reference/kotlin/androidx/camera/view/transform/OutputTransform)` Creates the transform between the `source` and the `target`. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/view/transform/CoordinateTransform#mapPoint(android.graphics.PointF)(point: https://developer.android.com/reference/android/graphics/PointF.html)` Apply this transform to the `https://developer.android.com/reference/android/graphics/PointF.html`, and write the transformed points back into the array |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/view/transform/CoordinateTransform#mapPoints(float[])(points: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>)` Apply this transform to the array of 2D points, and write the transformed points back into the array |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/view/transform/CoordinateTransform#mapRect(android.graphics.RectF)(rect: https://developer.android.com/reference/android/graphics/RectF.html)` Apply this transform to the rectangle, and write the transformed rectangle back into it. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/camera/view/transform/CoordinateTransform#transform(android.graphics.Matrix)(outMatrix: https://developer.android.com/reference/android/graphics/Matrix.html)` Copies the current transform to the specified `https://developer.android.com/reference/android/graphics/Matrix.html`. |

## Public constructors

### CoordinateTransform

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

```
CoordinateTransform(source: OutputTransform, target: OutputTransform)
```

Creates the transform between the `source` and the `target`.

The source and the target must be associated with the same `https://developer.android.com/reference/kotlin/androidx/camera/core/ViewPort`.

| Parameters |
|---|---|
| `source: https://developer.android.com/reference/kotlin/androidx/camera/view/transform/OutputTransform` | the source |
| `target: https://developer.android.com/reference/kotlin/androidx/camera/view/transform/OutputTransform` | the target |

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

## Public functions

### mapPoint

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

```
fun mapPoint(point: PointF): Unit
```

Apply this transform to the `https://developer.android.com/reference/android/graphics/PointF.html`, and write the transformed points back into the array

| Parameters |
|---|---|
| `point: https://developer.android.com/reference/android/graphics/PointF.html` | The point to transform. |

### mapPoints

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

```
fun mapPoints(points: FloatArray<Float>): Unit
```

Apply this transform to the array of 2D points, and write the transformed points back into the array

| Parameters |
|---|---|
| `points: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | The array \[x0, y0, x1, y1, ...\] of points to transform. |

| See also |
|---|---|
| `https://developer.android.com/reference/android/graphics/Matrix.html#mapPoints(float[])` |   |

### mapRect

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

```
fun mapRect(rect: RectF): Unit
```

Apply this transform to the rectangle, and write the transformed rectangle back into it. This is accomplished by transforming the 4 corners of rect, and then setting it to the bounds of those points.

| Parameters |
|---|---|
| `rect: https://developer.android.com/reference/android/graphics/RectF.html` | The rectangle to transform. |

### transform

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

```
fun transform(outMatrix: Matrix): Unit
```

Copies the current transform to the specified `https://developer.android.com/reference/android/graphics/Matrix.html`.

| Parameters |
|---|---|
| `outMatrix: https://developer.android.com/reference/android/graphics/Matrix.html` | a `https://developer.android.com/reference/android/graphics/Matrix.html` in which to copy the current transform. |