# PixelDensity

Artifact: [androidx.xr.scenecore:scenecore](https://developer.android.com/jetpack/androidx/releases/xr-scenecore) [View Source](https://cs.android.com/search?q=file:androidx/xr/scenecore/PixelDensity.kt+class:androidx.xr.scenecore.PixelDensity) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/xr-scenecore#1.0.0)

*** ** * ** ***


```
class PixelDensity
```

<br />

*** ** * ** ***

Represents a pixel density, analogous to the pixel density of a physical display like a computer monitor or TV. It defines the mapping between pixels and physical distance in meters.

Use this class to perform consistent unit conversions between the pixel-based coordinate systems and physical spatial dimensions.

## Summary

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PixelDensity#convertMetersToPixels(kotlin.Float)(meters: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Converts a physical distance in meters to a pixel count using this density. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PixelDensity#convertPixelsToMeters(kotlin.Float)(pixels: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Converts a pixel count to a physical distance in meters using this density. |

| ### Public properties |
|---|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, fromInclusive = false) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/scenecore/PixelDensity#pixelsPerMeter()` The number of pixels that correspond to one physical meter. |

## Public functions

### convertMetersToPixels

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

```
fun convertMetersToPixels(meters: Float): Float
```

Converts a physical distance in meters to a pixel count using this density.

### convertPixelsToMeters

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

```
fun convertPixelsToMeters(pixels: Float): Float
```

Converts a pixel count to a physical distance in meters using this density.

## Public properties

### pixelsPerMeter

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

```
val pixelsPerMeter: @FloatRange(from = 0.0, fromInclusive = false) Float
```

The number of pixels that correspond to one physical meter. Must be a positive and finite value.