# PixelMap

Artifact: [androidx.compose.ui:ui-graphics](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/graphics/PixelMap.kt+class:androidx.compose.ui.graphics.PixelMap) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/AllAndroid/JVM
- Cmn

  ```
  class PixelMap
  ```

*** ** * ** ***

Result of a pixel read operation. This contains the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` pixel information represented as a 1 dimensional array of values that supports queries of pixel values based on the 2 dimensional coordinates of the corresponding `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` this was obtained from

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.PixelMap

val imageBitmap = createImageBitmap()

val buffer = IntArray(20 * 10)
imageBitmap.readPixels(buffer = buffer, startX = 8, startY = 9, width = 20, height = 10)

val pixelmap = PixelMap(buffer = buffer, width = 20, height = 10, stride = 20, bufferOffset = 0)

// create a histogram to count the number of occurrences of a color within the specified
// subsection of the provided ImageBitmap
val histogram = HashMap<Color, Int>()
for (x in 0 until pixelmap.width) {
    for (y in 0 until pixelmap.height) {
        val color = pixelmap[x, y]
        val colorCount = histogram[color] ?: 0
        histogram[color] = (colorCount + 1)
    }
}
```

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap#readPixels(kotlin.IntArray,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/package-summary#(androidx.compose.ui.graphics.ImageBitmap).toPixelMap(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.IntArray,kotlin.Int,kotlin.Int)` |   |

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PixelMap#PixelMap(kotlin.IntArray,kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)( buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bufferOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, stride: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` | Cmn |

| ### Public functions |
|---|---|---|
| `operator https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PixelMap#get(kotlin.Int,kotlin.Int)(x: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, y: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Obtain the color of the pixel at the given coordinate. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PixelMap#buffer()` IntArray where pixel information is stored as an ARGB value packed into an Int | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PixelMap#bufferOffset()` first index in the buffer where pixel information for the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` is stored | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PixelMap#height()` Height of the subsection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` this buffer represents | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PixelMap#stride()` Number of entries to skip between rows | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/PixelMap#width()` Width of the subsection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` this buffer represents | Cmn |

## Public constructors

### PixelMap

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
PixelMap(
    buffer: IntArray,
    width: Int,
    height: Int,
    bufferOffset: Int,
    stride: Int
)
```

| Parameters |
|---|---|
| `buffer: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html` | IntArray where pixel information is stored as an ARGB value packed into an Int |
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Width of the subsection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` this buffer represents |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Height of the subsection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` this buffer represents |
| `bufferOffset: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | first index in the buffer where pixel information for the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` is stored |
| `stride: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Number of entries to skip between rows |

## Public functions

### get

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
operator fun get(x: @IntRange(from = 0) Int, y: @IntRange(from = 0) Int): Color
```

Obtain the color of the pixel at the given coordinate.

| Parameters |
|---|---|
| `x: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the horizontal pixel coordinate, minimum 1 |
| `y: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the vertical pixel coordinate, minimum 1 |

## Public properties

### buffer

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val buffer: IntArray
```

IntArray where pixel information is stored as an ARGB value packed into an Int

### bufferOffset

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val bufferOffset: Int
```

first index in the buffer where pixel information for the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` is stored

### height

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val height: Int
```

Height of the subsection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` this buffer represents

### stride

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val stride: Int
```

Number of entries to skip between rows

### width

Cmn Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0)

```
val width: Int
```

Width of the subsection of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` this buffer represents