core-ktx / androidx.graphics / android.graphics.Bitmap

Extensions for android.graphics.Bitmap

applyCanvas

fun Bitmap.applyCanvas(block: Canvas.() -> Unit): Bitmap

Creates a new Canvas to draw on this bitmap and executes the specified block on the newly created canvas. Example:

get

operator fun Bitmap.get(x: Int, y: Int): Int

Returns the value of the pixel at the specified location. The returned value is a color int in the sRGB color space.

scale

fun Bitmap.scale(width: Int, height: Int, filter: Boolean = true): Bitmap

Creates a new bitmap, scaled from this bitmap, when possible. If the specified width and height are the same as the current width and height of this bitmap, this bitmap is returned and no new bitmap is created.

set

operator fun Bitmap.set(x: Int, y: Int, color: Int): Unit

Writes the specified color int into the bitmap (assuming it is mutable) at the specified (x, y) coordinate. The specified color is converted from sRGB to the bitmap's color space if needed.