ImageBitmap

Interface

Common
@JvmDefaultWithCompatibility
interface ImageBitmap

Graphics object that represents a 2 dimensional array of pixel information represented as ARGB values

Properties

Common
val width: Int

The number of image pixels along the ImageBitmap's horizontal axis.

Common
val height: Int

The number of image pixels along the ImageBitmap's vertical axis.

Common
val colorSpace: ColorSpace

ColorSpace the Image renders in

Common
val hasAlpha: Boolean

Determines whether or not the ImageBitmap contains an alpha channel

Common
val config: ImageBitmapConfig

Returns the current configuration of this Image, either:

Functions

fun readPixels(
        buffer: IntArray,
        startX: Int = 0,
        startY: Int = 0,
        width: Int = this.width,
        height: Int = this.height,
        bufferOffset: Int = 0,
        stride: Int = width,
    )

Copies the pixel data within the ImageBitmap into the given array. Each value is represented as ARGB values packed into an Int. The stride parameter allows the caller to allow for gaps in the returned pixels array between rows. For normal packed, results, the stride value is equivalent to the width of the ImageBitmap. The returned colors are non-premultiplied ARGB values in the ColorSpaces.Srgb color space.

Note this method can block so it is recommended to not invoke this method in performance critical code paths

Parameters

bufferThe array to store the ImageBitmap's colors. By default this allocates an IntArray large enough to store all the pixel information. Consumers of this API are advised to use the smallest IntArray necessary to extract relevant pixel information, that is the 2 dimensional area of the section of the ImageBitmap to be queried.
startXThe x-coordinate of the first pixel to read from the ImageBitmap
startYThe y-coordinate of the first pixel to read from the ImageBitmap
widthThe number of pixels to read from each row
heightThe number of rows to read
bufferOffsetThe first index to write into the buffer array, this defaults to 0
strideThe number of entries in buffer to skip between rows (must be >= width
fun prepareToDraw()

Builds caches associated with the ImageBitmap that are used for drawing it. This method can be used as a signal to upload textures to the GPU to eventually be rendered