Google is committed to advancing racial equity for Black communities. See how.

PixelMap

class PixelMap
kotlin.Any
   ↳ androidx.ui.graphics.PixelMap

Result of a pixel read operation. This contains the ImageAsset 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 ImageAsset this was obtained from

import androidx.ui.graphics.PixelMap

val imageAsset = createImageAsset()

val buffer = IntArray(20 * 10)
imageAsset.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 ImageAsset
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)
    }
}

Summary

Public constructors
<init>(buffer: IntArray, width: Int, height: Int, bufferOffset: Int, stride: Int)

Result of a pixel read operation.

Public methods
operator Color
get(@IntRange(0) x: Int, @IntRange(0) y: Int)

Obtain the color of the pixel at the given coordinate

Properties
IntArray

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

Int

first index in the buffer where pixel information for the ImageAsset is stored

Int

Height of the subsection of the ImageAsset this buffer represents

Int

Number of entries to skip between rows

Int

Width of the subsection of the ImageAsset this buffer represents

Public constructors

<init>

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

Result of a pixel read operation. This contains the ImageAsset 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 ImageAsset this was obtained from

import androidx.ui.graphics.PixelMap

val imageAsset = createImageAsset()

val buffer = IntArray(20 * 10)
imageAsset.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 ImageAsset
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)
    }
}
Parameters
buffer: IntArray IntArray where pixel information is stored as an ARGB value packed into an Int
bufferOffset: Int first index in the buffer where pixel information for the ImageAsset is stored
width: Int Width of the subsection of the ImageAsset this buffer represents
height: Int Height of the subsection of the ImageAsset this buffer represents
stride: Int Number of entries to skip between rows

Public methods

get

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

Obtain the color of the pixel at the given coordinate

Properties

buffer

val buffer: IntArray

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

bufferOffset

val bufferOffset: Int

first index in the buffer where pixel information for the ImageAsset is stored

height

val height: Int

Height of the subsection of the ImageAsset this buffer represents

stride

val stride: Int

Number of entries to skip between rows

width

val width: Int

Width of the subsection of the ImageAsset this buffer represents