import { Meta } from '@storybook/addon-docs/blocks';

<Meta title="APIs|PixelRatio" />

# PixelRatio

PixelRatio class gives access to the device pixel density.

## Methods

### get()

Returns the device pixel density as a number.

### getFontScale()

On web this returns the device pixel ratio as a number.

### getPixelSizeForLayoutSize(number)

Converts a layout size (dp) to pixel size (px). Guaranteed to return an integer number.

```js
const image = getImage({
  width: PixelRatio.getPixelSizeForLayoutSize(200),
  height: PixelRatio.getPixelSizeForLayoutSize(100),
});

<Image source={image} style={{width: 200, height: 100}} />
```

### roundToNearestPixel(number)

Rounds a layout size (dp) to the nearest layout size that corresponds to an
integer number of pixels. For example, on a device with a PixelRatio of 3,
`PixelRatio.roundToNearestPixel(8.4) = 8.33`, which corresponds to exactly
`(8.33 * 3) = 25` pixels.
