androidx.core.graphics


Classes

BitmapCompat

Helper for accessing features in Bitmap.

BlendModeColorFilterCompat

Helper for accessing ColorFilter APIs on various API levels of the platform

ColorUtils

A set of color-related utility methods, building upon those available in Color.

Insets

An Insets instance holds four integer offsets which describe changes to the four edges of a Rectangle.

PaintCompat

Helper for accessing features in Paint.

PathParser

Parses SVG path strings.

PathParser.PathDataNode

Each PathDataNode represents one command in the "d" attribute of the svg file.

PathSegment

A line segment that represents an approximate fraction of a Path after flattening.

PathUtils

A set of path-related utility methods.

TypefaceCompat

Helper for accessing features in Typeface.

Enums

BlendModeCompat

Compat version of android.graphics.BlendMode, usages of BlendModeCompat will map to android.graphics.PorterDuff.Mode wherever possible

Top-level functions summary

inline Bitmap
createBitmap(width: Int, height: Int, config: Bitmap.Config)

Returns a mutable bitmap with the specified width and height.

inline Bitmap
@RequiresApi(value = 26)
createBitmap(
    width: Int,
    height: Int,
    config: Bitmap.Config,
    hasAlpha: Boolean,
    colorSpace: ColorSpace
)

Returns a mutable bitmap with the specified width and height.

Matrix
rotationMatrix(degrees: Float, px: Float, py: Float)

Creates a rotation matrix, defined by a rotation angle in degrees around the pivot point located at the coordinates (px, py).

Matrix
scaleMatrix(sx: Float, sy: Float)

Creates a scale matrix with the scale factor sx and sy respectively on the x and y axis.

Matrix

Creates a translation matrix with the translation amounts tx and ty respectively on the x and y axis.

Extension functions summary

inline infix Path

Returns the intersection of two paths as a new Path.

inline infix Rect

Returns the intersection of two rectangles as a new rectangle.

inline infix Region

Return the intersection of this region and the specified Rect as a new region.

inline infix RectF

Returns the intersection of two rectangles as a new rectangle.

inline infix Region

Return the intersection of this region and the specified region as a new region.

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

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

inline operator Float
@RequiresApi(value = 26)
Color.component1()

Returns the first component of the color.

inline operator Int

Return the alpha component of a color int.

inline operator Float

Returns the first component of the color.

inline operator Int

Returns the x coordinate of this point.

inline operator Float

Returns the x coordinate of this point.

inline operator Int

Returns "left", the first component of the rectangle.

inline operator Float

Returns "left", the first component of the rectangle.

inline operator Float
@RequiresApi(value = 26)
Color.component2()

Returns the second component of the color.

inline operator Int

Return the red component of a color int.

inline operator Float

Returns the second component of the color.

inline operator Int

Returns the y coordinate of this point.

inline operator Float

Returns the y coordinate of this point.

inline operator Int

Returns "top", the second component of the rectangle.

inline operator Float

Returns "top", the second component of the rectangle.

inline operator Float
@RequiresApi(value = 26)
Color.component3()

Returns the third component of the color.

inline operator Int

Return the green component of a color int.

inline operator Float

Returns the third component of the color.

inline operator Int

Returns "right", the third component of the rectangle.

inline operator Float

Returns "right", the third component of the rectangle.

inline operator Float
@RequiresApi(value = 26)
Color.component4()

Returns the fourth component of the color.

inline operator Int

Return the blue component of a color int.

inline operator Float

Returns the fourth component of the color.

inline operator Int

Returns "bottom", the fourth component of the rectangle.

inline operator Float

Returns "bottom", the fourth component of the rectangle.

inline operator Boolean

Returns true if the specified point is inside the bitmap.

inline operator Boolean

Returns true if the specified point is inside the rectangle.

inline operator Boolean

Return true if the region contains the specified Point.

inline operator Boolean

Returns true if the specified point is inside the bitmap.

inline operator Boolean

Returns true if the specified point is inside the rectangle.

inline infix @ColorLong Long
@RequiresApi(value = 26)
@ColorInt Int.convertTo(colorSpace: ColorSpace)

Converts the color int receiver to a color long in the specified color space.

inline infix @ColorLong Long
@RequiresApi(value = 26)
@ColorLong Long.convertTo(colorSpace: ColorSpace)

Converts the color long receiver to a color long in the specified color space.

inline infix Color
@RequiresApi(value = 26)
Color.convertTo(colorSpace: ColorSpace)

Converts the color receiver to a color in the specified color space.

inline infix @ColorLong Long
@RequiresApi(value = 26)
@ColorInt Int.convertTo(colorSpace: ColorSpace.Named)

Converts the color int receiver to a color long in the specified color space.

inline infix @ColorLong Long
@RequiresApi(value = 26)
@ColorLong Long.convertTo(colorSpace: ColorSpace.Named)

Converts the color long receiver to a color long in the specified color space.

inline infix Color
@RequiresApi(value = 26)
Color.convertTo(colorSpace: ColorSpace.Named)

Converts the color receiver to a color in the specified color space.

inline Bitmap
@RequiresApi(value = 28)
ImageDecoder.Source.decodeBitmap(
    crossinline action: ImageDecoder.(info: ImageDecoder.ImageInfo, source: ImageDecoder.Source) -> Unit
)

Create a Bitmap from a Source

inline Drawable
@RequiresApi(value = 28)
ImageDecoder.Source.decodeDrawable(
    crossinline action: ImageDecoder.(info: ImageDecoder.ImageInfo, source: ImageDecoder.Source) -> Unit
)

Create a Drawable from a Source

inline operator Point
Point.div(scalar: Float)

Divides this point by the specified scalar value and returns the result as a new point.

inline operator PointF
PointF.div(scalar: Float)

Divides this point by the specified scalar value and returns the result as a new point.

Iterable<PathSegment>
@RequiresApi(value = 26)
Path.flatten(error: Float)

Flattens (or approximate) the Path with a series of line segments.

inline Unit
Region.forEach(action: (rect: Rect) -> Unit)

Performs the given action on each rect in this region.

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

Returns the value of the pixel at the specified location.

operator Iterator<Rect>

Returns an Iterator over the rects in this region.

inline operator Path

Returns the difference of two paths as a new Path.

inline operator Point

Offsets this point by the negation of the specified point and returns the result as a new point.

inline operator PointF

Offsets this point by the negation of the specified point and returns the result as a new point.

inline operator Region

Returns the difference of this rectangle and the specified rectangle as a new region.

inline operator Region

Return the difference of this region and the specified Rect as a new region.

inline operator Region

Returns the difference of this rectangle and the specified rectangle as a new region.

inline operator Region

Return the difference of this region and the specified region as a new region.

inline operator PointF

Offsets this point by the negation of the specified amount on both X and Y axis and returns the result as a new point.

inline operator RectF

Returns a new rectangle representing this rectangle offset by the negation of the specified amount on both X and Y axis.

inline operator Point

Offsets this point by the negation of the specified amount on both X and Y axis and returns the result as a new point.

inline operator Rect
Rect.minus(xy: Int)

Returns a new rectangle representing this rectangle offset by the negation of the specified amount on both X and Y axis.

inline operator Rect

Returns a new rectangle representing this rectangle offset by the negation of the specified point.

inline operator RectF

Returns a new rectangle representing this rectangle offset by the negation of the specified point.

inline operator Region

Returns the negation of this region as a new region.

inline infix Path
Path.or(p: Path)

Returns the union of two paths as a new Path.

inline infix Rect
Rect.or(r: Rect)

Returns the union of two rectangles as a new rectangle.

inline infix Region

Return the union of this region and the specified Rect as a new region.

inline infix RectF

Returns the union of two rectangles as a new rectangle.

inline infix Region

Return the union of this region and the specified region as a new region.

operator Color
@RequiresApi(value = 26)
Color.plus(c: Color)

Composites two translucent colors together.

inline operator Path

Returns the union of two paths as a new Path.

inline operator Point

Offsets this point by the specified point and returns the result as a new point.

inline operator PointF

Offsets this point by the specified point and returns the result as a new point.

inline operator Rect

Performs the union of this rectangle and the specified rectangle and returns the result as a new rectangle.

inline operator Region

Return the union of this region and the specified Rect as a new region.

inline operator RectF

Performs the union of this rectangle and the specified rectangle and returns the result as a new rectangle.

inline operator Region

Return the union of this region and the specified region as a new region.

inline operator PointF

Offsets this point by the specified amount on both X and Y axis and returns the result as a new point.

inline operator RectF

Returns a new rectangle representing this rectangle offset by the specified amount on both X and Y axis.

inline operator Point
Point.plus(xy: Int)

Offsets this point by the specified amount on both X and Y axis and returns the result as a new point.

inline operator Rect
Rect.plus(xy: Int)

Returns a new rectangle representing this rectangle offset by the specified amount on both X and Y axis.

inline operator Rect

Returns a new rectangle representing this rectangle offset by the specified point.

inline operator RectF

Returns a new rectangle representing this rectangle offset by the specified point.

inline Picture
Picture.record(width: Int, height: Int, block: Canvas.() -> Unit)

Creates a new Canvas to record commands in this Picture, executes the specified block on the newly created canvas and returns this Picture.

inline Bitmap
Bitmap.scale(width: Int, height: Int, filter: Boolean)

Creates a new bitmap, scaled from this bitmap, when possible.

inline operator Unit
Bitmap.set(x: Int, y: Int, color: @ColorInt Int)

Writes the specified color int into the bitmap (assuming it is mutable) at the specified (x, y) coordinate.

inline Boolean
Paint.setBlendMode(blendModeCompat: BlendModeCompat?)

Convenience method to configure the BlendMode of a Paint in a backward compatible way.

inline operator RectF
RectF.times(factor: Float)

Returns a new rectangle representing this rectangle's components each scaled by factor.

inline operator Rect
Rect.times(factor: Int)

Returns a new rectangle representing this rectangle's components each scaled by factor.

inline operator RectF
RectF.times(factor: Int)

Returns a new rectangle representing this rectangle's components each scaled by factor.

inline operator Matrix

Multiplies this Matrix by another matrix and returns the result as a new matrix.

inline operator Point
Point.times(scalar: Float)

Multiplies this point by the specified scalar value and returns the result as a new point.

inline operator PointF
PointF.times(scalar: Float)

Multiplies this point by the specified scalar value and returns the result as a new point.

inline Color
@RequiresApi(value = 26)
@ColorInt Int.toColor()

Creates a new Color instance from a color int.

inline Color

Creates a new Color instance from a color long.

inline PorterDuffColorFilter

Creates a new PorterDuffColorFilter that uses this PorterDuff.Mode as the alpha compositing or blending mode, and the specified color.

inline @ColorInt Int

Converts the specified color long to an ARGB color int.

inline @ColorInt Int

Return a corresponding Int color of this String.

inline @ColorLong Long

Converts the specified ARGB color int to an RGBA color long in the sRGB color space.

inline Point

Returns a Point representation of this point.

inline PointF

Returns a PointF representation of this point.

inline Rect

Returns a Rect representation of this rectangle.

inline RectF

Returns a RectF representation of this rectangle.

inline Region

Returns a Region representation of this rectangle.

inline Region

Returns a Region representation of this rectangle.

inline PorterDuffXfermode

Creates a new PorterDuffXfermode that uses this PorterDuff.Mode as the alpha compositing or blending mode.

inline Unit
Shader.transform(block: Matrix.() -> Unit)

Wrap the specified block in calls to Shader.getLocalMatrix and Shader.setLocalMatrix.

inline RectF

Transform this rectangle in place using the supplied Matrix and returns this rectangle.

inline operator Point

Returns a new point representing the negation of this point.

inline operator PointF

Returns a new point representing the negation of this point.

inline operator Region

Returns the negation of this region as a new region.

inline FloatArray

Returns the 9 values of this Matrix as a new array of floats.

inline Unit
Canvas.withClip(clipPath: Path, block: Canvas.() -> Unit)

Wrap the specified block in calls to Canvas.save/Canvas.clipPath and Canvas.restoreToCount.

inline Unit
Canvas.withClip(clipRect: Rect, block: Canvas.() -> Unit)

Wrap the specified block in calls to Canvas.save/Canvas.clipRect and Canvas.restoreToCount.

inline Unit
Canvas.withClip(clipRect: RectF, block: Canvas.() -> Unit)

Wrap the specified block in calls to Canvas.save/Canvas.clipRect and Canvas.restoreToCount.

inline Unit
Canvas.withClip(
    left: Float,
    top: Float,
    right: Float,
    bottom: Float,
    block: Canvas.() -> Unit
)

Wrap the specified block in calls to Canvas.save/Canvas.clipRect and Canvas.restoreToCount.

inline Unit
Canvas.withClip(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int,
    block: Canvas.() -> Unit
)

Wrap the specified block in calls to Canvas.save/Canvas.clipRect and Canvas.restoreToCount.

inline Unit
Canvas.withMatrix(matrix: Matrix, block: Canvas.() -> Unit)

Wrap the specified block in calls to Canvas.save/Canvas.concat and Canvas.restoreToCount.

inline Unit
Canvas.withRotation(
    degrees: Float,
    pivotX: Float,
    pivotY: Float,
    block: Canvas.() -> Unit
)

Wrap the specified block in calls to Canvas.save/Canvas.rotate and Canvas.restoreToCount.

inline Unit
Canvas.withSave(block: Canvas.() -> Unit)

Wrap the specified block in calls to Canvas.save and Canvas.restoreToCount.

inline Unit
Canvas.withScale(
    x: Float,
    y: Float,
    pivotX: Float,
    pivotY: Float,
    block: Canvas.() -> Unit
)

Wrap the specified block in calls to Canvas.save/Canvas.scale and Canvas.restoreToCount.

inline Unit
Canvas.withSkew(x: Float, y: Float, block: Canvas.() -> Unit)

Wrap the specified block in calls to Canvas.save/Canvas.skew and Canvas.restoreToCount.

inline Unit
Canvas.withTranslation(x: Float, y: Float, block: Canvas.() -> Unit)

Wrap the specified block in calls to Canvas.save/Canvas.translate and Canvas.restoreToCount.

inline infix Path

Returns the union minus the intersection of two paths as a new Path.

inline infix Region

Returns the union minus the intersection of two rectangles as a new region.

inline infix Region

Return the union minus the intersection of this region and the specified Rect as a new region.

inline infix Region

Returns the union minus the intersection of two rectangles as a new region.

inline infix Region

Return the union minus the intersection of this region and the specified region as a new region.

Extension properties summary

Int

Return the alpha component of a color int.

Float

Return the alpha component of a color long.

Int

Return the blue component of a color int.

Float

Return the blue component of a color long.

ColorSpace

Returns the color space encoded in the specified color long.

Int

Return the green component of a color int.

Float

Return the green component of a color long.

Boolean

Indicates whether the color is in the sRGB color space.

Boolean

Indicates whether the color is in a wide-gamut color space.

Float

Returns the relative luminance of a color int, assuming sRGB encoding.

Float

Returns the relative luminance of a color.

Int

Return the red component of a color int.

Float

Return the red component of a color long.

Top-level functions

createBitmap

inline fun createBitmap(
    width: Int,
    height: Int,
    config: Bitmap.Config = Bitmap.Config.ARGB_8888
): Bitmap

Returns a mutable bitmap with the specified width and height. A config can be optionally specified. If not, the default config is Bitmap.Config.ARGB_8888.

Parameters
width: Int

The new bitmap's desired width

height: Int

The new bitmap's desired height

config: Bitmap.Config = Bitmap.Config.ARGB_8888

The new bitmap's desired config

Returns
Bitmap

A new bitmap with the specified dimensions and config

createBitmap

@RequiresApi(value = 26)
inline fun createBitmap(
    width: Int,
    height: Int,
    config: Bitmap.Config = Bitmap.Config.ARGB_8888,
    hasAlpha: Boolean = true,
    colorSpace: ColorSpace = ColorSpace.get(ColorSpace.Named.SRGB)
): Bitmap

Returns a mutable bitmap with the specified width and height. The config, transparency and color space can optionally be specified. They respectively default to Bitmap.Config.ARGB_8888, true and sRGB.

Parameters
width: Int

The new bitmap's desired width

height: Int

The new bitmap's desired height

config: Bitmap.Config = Bitmap.Config.ARGB_8888

The new bitmap's desired config

hasAlpha: Boolean = true

Whether the new bitmap is opaque or not

colorSpace: ColorSpace = ColorSpace.get(ColorSpace.Named.SRGB)

The new bitmap's color space

Returns
Bitmap

A new bitmap with the specified dimensions and config

rotationMatrix

fun rotationMatrix(degrees: Float, px: Float = 0.0f, py: Float = 0.0f): Matrix

Creates a rotation matrix, defined by a rotation angle in degrees around the pivot point located at the coordinates (px, py).

scaleMatrix

fun scaleMatrix(sx: Float = 1.0f, sy: Float = 1.0f): Matrix

Creates a scale matrix with the scale factor sx and sy respectively on the x and y axis.

translationMatrix

fun translationMatrix(tx: Float = 0.0f, ty: Float = 0.0f): Matrix

Creates a translation matrix with the translation amounts tx and ty respectively on the x and y axis.

Extension functions

and

inline infix fun Path.and(p: Path): Path

Returns the intersection of two paths as a new Path. If the paths do not intersect, returns an empty path.

and

inline infix fun Rect.and(r: Rect): Rect

Returns the intersection of two rectangles as a new rectangle. If the rectangles do not intersect, returns a copy of the left hand side rectangle.

and

inline infix fun Region.and(r: Rect): Region

Return the intersection of this region and the specified Rect as a new region.

and

inline infix fun RectF.and(r: RectF): RectF

Returns the intersection of two rectangles as a new rectangle. If the rectangles do not intersect, returns a copy of the left hand side rectangle.

and

inline infix fun Region.and(r: Region): Region

Return the intersection of this region and the specified region as a new region.

applyCanvas

inline 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:

return Bitmap.createBitmap(…).applyCanvas {
drawLine(…)
translate(…)
drawRect(…)
}

component1

@RequiresApi(value = 26)
inline operator fun Color.component1(): Float

Returns the first component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the first component is "red".

This method allows to use destructuring declarations when working with colors, for example:

val (red, green, blue) = myColor

component1

inline operator fun @ColorInt Int.component1(): Int

Return the alpha component of a color int. This is equivalent to calling:

Color.alpha(myInt)

This method allows to use destructuring declarations when working with colors, for example:

val (alpha, red, green, blue) = myColor

component1

@RequiresApi(value = 26)
inline operator fun @ColorLong Long.component1(): Float

Returns the first component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the first component is "red".

This method allows to use destructuring declarations when working with colors, for example:

val (red, green, blue, alpha) = myColorLong

component1

inline operator fun Point.component1(): Int

Returns the x coordinate of this point.

This method allows to use destructuring declarations when working with points, for example:

val (x, y) = myPoint

component1

inline operator fun PointF.component1(): Float

Returns the x coordinate of this point.

This method allows to use destructuring declarations when working with points, for example:

val (x, y) = myPoint

component1

inline operator fun Rect.component1(): Int

Returns "left", the first component of the rectangle.

This method allows to use destructuring declarations when working with rectangles, for example:

val (left, top, right, bottom) = myRectangle

component1

inline operator fun RectF.component1(): Float

Returns "left", the first component of the rectangle.

This method allows to use destructuring declarations when working with rectangles, for example:

val (left, top, right, bottom) = myRectangle

component2

@RequiresApi(value = 26)
inline operator fun Color.component2(): Float

Returns the second component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the second component is "green".

This method allows to use destructuring declarations when working with colors, for example:

val (red, green, blue) = myColor

component2

inline operator fun @ColorInt Int.component2(): Int

Return the red component of a color int. This is equivalent to calling:

Color.red(myInt)

This method allows to use destructuring declarations when working with colors, for example:

val (alpha, red, green, blue) = myColor

component2

@RequiresApi(value = 26)
inline operator fun @ColorLong Long.component2(): Float

Returns the second component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the second component is "green".

This method allows to use destructuring declarations when working with colors, for example:

val (red, green, blue, alpha) = myColorLong

component2

inline operator fun Point.component2(): Int

Returns the y coordinate of this point.

This method allows to use destructuring declarations when working with points, for example:

val (x, y) = myPoint

component2

inline operator fun PointF.component2(): Float

Returns the y coordinate of this point.

This method allows to use destructuring declarations when working with points, for example:

val (x, y) = myPoint

component2

inline operator fun Rect.component2(): Int

Returns "top", the second component of the rectangle.

This method allows to use destructuring declarations when working with rectangles, for example:

val (left, top, right, bottom) = myRectangle

component2

inline operator fun RectF.component2(): Float

Returns "top", the second component of the rectangle.

This method allows to use destructuring declarations when working with rectangles, for example:

val (left, top, right, bottom) = myRectangle

component3

@RequiresApi(value = 26)
inline operator fun Color.component3(): Float

Returns the third component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the third component is "blue". = * This method allows to use destructuring declarations when working with colors, for example:

val (red, green, blue) = myColor

component3

inline operator fun @ColorInt Int.component3(): Int

Return the green component of a color int. This is equivalent to calling:

Color.green(myInt)

This method allows to use destructuring declarations when working with colors, for example:

val (alpha, red, green, blue) = myColor

component3

@RequiresApi(value = 26)
inline operator fun @ColorLong Long.component3(): Float

Returns the third component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the third component is "blue".

This method allows to use destructuring declarations when working with colors, for example:

val (red, green, blue, alpha) = myColorLong

component3

inline operator fun Rect.component3(): Int

Returns "right", the third component of the rectangle.

This method allows to use destructuring declarations when working with rectangles, for example:

val (left, top, right, bottom) = myRectangle

component3

inline operator fun RectF.component3(): Float

Returns "right", the third component of the rectangle.

This method allows to use destructuring declarations when working with rectangles, for example:

val (left, top, right, bottom) = myRectangle

component4

@RequiresApi(value = 26)
inline operator fun Color.component4(): Float

Returns the fourth component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the fourth component is "alpha".

This method allows to use destructuring declarations when working with colors, for example:

val (red, green, blue, alpha) = myColor

component4

inline operator fun @ColorInt Int.component4(): Int

Return the blue component of a color int. This is equivalent to calling:

Color.blue(myInt)

This method allows to use destructuring declarations when working with colors, for example:

val (alpha, red, green, blue) = myColor

component4

@RequiresApi(value = 26)
inline operator fun @ColorLong Long.component4(): Float

Returns the fourth component of the color. For instance, when the color model of the color is android.graphics.ColorSpace.Model.RGB, the fourth component is "alpha".

This method allows to use destructuring declarations when working with colors, for example:

val (red, green, blue, alpha) = myColorLong

component4

inline operator fun Rect.component4(): Int

Returns "bottom", the fourth component of the rectangle.

This method allows to use destructuring declarations when working with rectangles, for example:

val (left, top, right, bottom) = myRectangle

component4

inline operator fun RectF.component4(): Float

Returns "bottom", the fourth component of the rectangle.

This method allows to use destructuring declarations when working with rectangles, for example:

val (left, top, right, bottom) = myRectangle

contains

inline operator fun Bitmap.contains(p: Point): Boolean

Returns true if the specified point is inside the bitmap. A point is contained if: 0 <= x < width and 0 <= y < height. An empty bitmap never contains any point.

contains

inline operator fun Rect.contains(p: Point): Boolean

Returns true if the specified point is inside the rectangle. The left and top are considered to be inside, while the right and bottom are not. This means that for a point to be contained: left <= x < right and top <= y < bottom. An empty rectangle never contains any point.

contains

inline operator fun Region.contains(p: Point): Boolean

Return true if the region contains the specified Point.

contains

inline operator fun Bitmap.contains(p: PointF): Boolean

Returns true if the specified point is inside the bitmap. A point is contained if: 0 <= x < width and 0 <= y < height. An empty bitmap never contains any point.

contains

inline operator fun RectF.contains(p: PointF): Boolean

Returns true if the specified point is inside the rectangle. The left and top are considered to be inside, while the right and bottom are not. This means that for a point to be contained: left <= x < right and top <= y < bottom. An empty rectangle never contains any point.

convertTo

@RequiresApi(value = 26)
inline infix fun @ColorInt Int.convertTo(colorSpace: ColorSpace): @ColorLong Long

Converts the color int receiver to a color long in the specified color space. This is equivalent to calling:

Color.convert(myColorInt, colorSpace)

convertTo

@RequiresApi(value = 26)
inline infix fun @ColorLong Long.convertTo(colorSpace: ColorSpace): @ColorLong Long

Converts the color long receiver to a color long in the specified color space. This is equivalent to calling:

Color.convert(myColorLong, colorSpace)

convertTo

@RequiresApi(value = 26)
inline infix fun Color.convertTo(colorSpace: ColorSpace): Color

Converts the color receiver to a color in the specified color space. This is equivalent to calling:

myColor.convert(colorSpace)

convertTo

@RequiresApi(value = 26)
inline infix fun @ColorInt Int.convertTo(colorSpace: ColorSpace.Named): @ColorLong Long

Converts the color int receiver to a color long in the specified color space. This is equivalent to calling:

Color.convert(myColorInt, ColorSpace.get(colorSpace))

convertTo

@RequiresApi(value = 26)
inline infix fun @ColorLong Long.convertTo(colorSpace: ColorSpace.Named): @ColorLong Long

Converts the color long receiver to a color long in the specified color space. This is equivalent to calling:

Color.convert(myColorLong, ColorSpace.get(colorSpace))

convertTo

@RequiresApi(value = 26)
inline infix fun Color.convertTo(colorSpace: ColorSpace.Named): Color

Converts the color receiver to a color in the specified color space. This is equivalent to calling:

myColor.convert(ColorSpace.get(colorSpace))

decodeBitmap

@RequiresApi(value = 28)
inline fun ImageDecoder.Source.decodeBitmap(
    crossinline action: ImageDecoder.(info: ImageDecoder.ImageInfo, source: ImageDecoder.Source) -> Unit
): Bitmap

Create a Bitmap from a Source

See also
decodeBitmap

decodeDrawable

@RequiresApi(value = 28)
inline fun ImageDecoder.Source.decodeDrawable(
    crossinline action: ImageDecoder.(info: ImageDecoder.ImageInfo, source: ImageDecoder.Source) -> Unit
): Drawable

Create a Drawable from a Source

See also
decodeDrawable

div

inline operator fun Point.div(scalar: Float): Point

Divides this point by the specified scalar value and returns the result as a new point.

div

inline operator fun PointF.div(scalar: Float): PointF

Divides this point by the specified scalar value and returns the result as a new point.

flatten

@RequiresApi(value = 26)
fun Path.flatten(error: Float = 0.5f): Iterable<PathSegment>

Flattens (or approximate) the Path with a series of line segments.

Parameters
error: Float = 0.5f

The acceptable error for a line on the Path in pixels. Typically this would be 0.5 so that the error is less than half a pixel. This value must be positive and is set to 0.5 by default.

See also
approximate

forEach

inline fun Region.forEach(action: (rect: Rect) -> Unit): Unit

Performs the given action on each rect in this region.

get

inline 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.

iterator

operator fun Region.iterator(): Iterator<Rect>

Returns an Iterator over the rects in this region.

minus

inline operator fun Path.minus(p: Path): Path

Returns the difference of two paths as a new Path.

minus

inline operator fun Point.minus(p: Point): Point

Offsets this point by the negation of the specified point and returns the result as a new point.

minus

inline operator fun PointF.minus(p: PointF): PointF

Offsets this point by the negation of the specified point and returns the result as a new point.

minus

inline operator fun Rect.minus(r: Rect): Region

Returns the difference of this rectangle and the specified rectangle as a new region.

minus

inline operator fun Region.minus(r: Rect): Region

Return the difference of this region and the specified Rect as a new region.

minus

inline operator fun RectF.minus(r: RectF): Region

Returns the difference of this rectangle and the specified rectangle as a new region. This rectangle is first converted to a Rect using RectF.toRect.

minus

inline operator fun Region.minus(r: Region): Region

Return the difference of this region and the specified region as a new region.

minus

inline operator fun PointF.minus(xy: Float): PointF

Offsets this point by the negation of the specified amount on both X and Y axis and returns the result as a new point.

minus

inline operator fun RectF.minus(xy: Float): RectF

Returns a new rectangle representing this rectangle offset by the negation of the specified amount on both X and Y axis.

minus

inline operator fun Point.minus(xy: Int): Point

Offsets this point by the negation of the specified amount on both X and Y axis and returns the result as a new point.

minus

inline operator fun Rect.minus(xy: Int): Rect

Returns a new rectangle representing this rectangle offset by the negation of the specified amount on both X and Y axis.

minus

inline operator fun Rect.minus(xy: Point): Rect

Returns a new rectangle representing this rectangle offset by the negation of the specified point.

minus

inline operator fun RectF.minus(xy: PointF): RectF

Returns a new rectangle representing this rectangle offset by the negation of the specified point.

not

inline operator fun Region.not(): Region

Returns the negation of this region as a new region.

or

inline infix fun Path.or(p: Path): Path

Returns the union of two paths as a new Path.

or

inline infix fun Rect.or(r: Rect): Rect

Returns the union of two rectangles as a new rectangle.

or

inline infix fun Region.or(r: Rect): Region

Return the union of this region and the specified Rect as a new region.

or

inline infix fun RectF.or(r: RectF): RectF

Returns the union of two rectangles as a new rectangle.

or

inline infix fun Region.or(r: Region): Region

Return the union of this region and the specified region as a new region.

plus

@RequiresApi(value = 26)
operator fun Color.plus(c: Color): Color

Composites two translucent colors together. More specifically, adds two colors using the source over blending mode. The colors must not be pre-multiplied and the result is a non pre-multiplied color.

If the two colors have different color spaces, the color in the right-hand part of the expression is converted to the color space of the color in left-hand part of the expression.

The following example creates a purple color by blending opaque blue with semi-translucent red:

val purple = Color.valueOf(0f, 0f, 1f) + Color.valueOf(1f, 0f, 0f, 0.5f)
Throws
kotlin.IllegalArgumentException

if the color models of the colors do not match

plus

inline operator fun Path.plus(p: Path): Path

Returns the union of two paths as a new Path.

plus

inline operator fun Point.plus(p: Point): Point

Offsets this point by the specified point and returns the result as a new point.

plus

inline operator fun PointF.plus(p: PointF): PointF

Offsets this point by the specified point and returns the result as a new point.

plus

inline operator fun Rect.plus(r: Rect): Rect

Performs the union of this rectangle and the specified rectangle and returns the result as a new rectangle.

plus

inline operator fun Region.plus(r: Rect): Region

Return the union of this region and the specified Rect as a new region.

plus

inline operator fun RectF.plus(r: RectF): RectF

Performs the union of this rectangle and the specified rectangle and returns the result as a new rectangle.

plus

inline operator fun Region.plus(r: Region): Region

Return the union of this region and the specified region as a new region.

plus

inline operator fun PointF.plus(xy: Float): PointF

Offsets this point by the specified amount on both X and Y axis and returns the result as a new point.

plus

inline operator fun RectF.plus(xy: Float): RectF

Returns a new rectangle representing this rectangle offset by the specified amount on both X and Y axis.

plus

inline operator fun Point.plus(xy: Int): Point

Offsets this point by the specified amount on both X and Y axis and returns the result as a new point.

plus

inline operator fun Rect.plus(xy: Int): Rect

Returns a new rectangle representing this rectangle offset by the specified amount on both X and Y axis.

plus

inline operator fun Rect.plus(xy: Point): Rect

Returns a new rectangle representing this rectangle offset by the specified point.

plus

inline operator fun RectF.plus(xy: PointF): RectF

Returns a new rectangle representing this rectangle offset by the specified point.

record

inline fun Picture.record(width: Int, height: Int, block: Canvas.() -> Unit): Picture

Creates a new Canvas to record commands in this Picture, executes the specified block on the newly created canvas and returns this Picture. Example:

return myPicture.record(1280, 720) {
drawLine(…)
translate(…)
drawRect(…)
}

scale

inline 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.

Parameters
width: Int

The new bitmap's desired width

height: Int

The new bitmap's desired height

filter: Boolean = true

true if the source should be filtered (true by default)

Returns
Bitmap

The new scaled bitmap or the source bitmap if no scaling is required.

set

inline operator fun Bitmap.set(x: Int, y: Int, color: @ColorInt 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.

setBlendMode

inline fun Paint.setBlendMode(blendModeCompat: BlendModeCompat?): Boolean

Convenience method to configure the BlendMode of a Paint in a backward compatible way. This method is a no-op for BlendModes that have no equivalent on older API levels

times

inline operator fun RectF.times(factor: Float): RectF

Returns a new rectangle representing this rectangle's components each scaled by factor.

times

inline operator fun Rect.times(factor: Int): Rect

Returns a new rectangle representing this rectangle's components each scaled by factor.

times

inline operator fun RectF.times(factor: Int): RectF

Returns a new rectangle representing this rectangle's components each scaled by factor.

times

inline operator fun Matrix.times(m: Matrix): Matrix

Multiplies this Matrix by another matrix and returns the result as a new matrix.

times

inline operator fun Point.times(scalar: Float): Point

Multiplies this point by the specified scalar value and returns the result as a new point.

times

inline operator fun PointF.times(scalar: Float): PointF

Multiplies this point by the specified scalar value and returns the result as a new point.

toColor

@RequiresApi(value = 26)
inline fun @ColorInt Int.toColor(): Color

Creates a new Color instance from a color int. The resulting color is in the sRGB color space.

toColor

@RequiresApi(value = 26)
inline fun @ColorLong Long.toColor(): Color

Creates a new Color instance from a color long.

toColorFilter

inline fun PorterDuff.Mode.toColorFilter(color: Int): PorterDuffColorFilter

Creates a new PorterDuffColorFilter that uses this PorterDuff.Mode as the alpha compositing or blending mode, and the specified color.

toColorInt

@RequiresApi(value = 26)
inline fun @ColorLong Long.toColorInt(): @ColorInt Int

Converts the specified color long to an ARGB color int.

toColorInt

inline fun String.toColorInt(): @ColorInt Int

Return a corresponding Int color of this String.

Supported formats are:

#RRGGBB
#AARRGGBB

The following names are also accepted: "red", "blue", "green", "black", "white", "gray", "cyan", "magenta", "yellow", "lightgray", "darkgray", "grey", "lightgrey", "darkgrey", "aqua", "fuchsia", "lime", "maroon", "navy", "olive", "purple", "silver", "teal".

Throws
kotlin.IllegalArgumentException

if this String cannot be parsed.

toColorLong

@RequiresApi(value = 26)
inline fun @ColorInt Int.toColorLong(): @ColorLong Long

Converts the specified ARGB color int to an RGBA color long in the sRGB color space.

toPoint

inline fun PointF.toPoint(): Point

Returns a Point representation of this point.

toPointF

inline fun Point.toPointF(): PointF

Returns a PointF representation of this point.

toRect

inline fun RectF.toRect(): Rect

Returns a Rect representation of this rectangle. The resulting rect will be sized such that this rect can fit within it.

toRectF

inline fun Rect.toRectF(): RectF

Returns a RectF representation of this rectangle.

toRegion

inline fun Rect.toRegion(): Region

Returns a Region representation of this rectangle.

toRegion

inline fun RectF.toRegion(): Region

Returns a Region representation of this rectangle. The resulting rect will be sized such that this rect can fit within it.

toXfermode

inline fun PorterDuff.Mode.toXfermode(): PorterDuffXfermode

Creates a new PorterDuffXfermode that uses this PorterDuff.Mode as the alpha compositing or blending mode.

transform

inline fun Shader.transform(block: Matrix.() -> Unit): Unit

Wrap the specified block in calls to Shader.getLocalMatrix and Shader.setLocalMatrix.

transform

inline fun RectF.transform(m: Matrix): RectF

Transform this rectangle in place using the supplied Matrix and returns this rectangle.

unaryMinus

inline operator fun Point.unaryMinus(): Point

Returns a new point representing the negation of this point.

unaryMinus

inline operator fun PointF.unaryMinus(): PointF

Returns a new point representing the negation of this point.

unaryMinus

inline operator fun Region.unaryMinus(): Region

Returns the negation of this region as a new region.

values

inline fun Matrix.values(): FloatArray

Returns the 9 values of this Matrix as a new array of floats.

withClip

inline fun Canvas.withClip(clipPath: Path, block: Canvas.() -> Unit): Unit

Wrap the specified block in calls to Canvas.save/Canvas.clipPath and Canvas.restoreToCount.

withClip

inline fun Canvas.withClip(clipRect: Rect, block: Canvas.() -> Unit): Unit

Wrap the specified block in calls to Canvas.save/Canvas.clipRect and Canvas.restoreToCount.

withClip

inline fun Canvas.withClip(clipRect: RectF, block: Canvas.() -> Unit): Unit

Wrap the specified block in calls to Canvas.save/Canvas.clipRect and Canvas.restoreToCount.

withClip

inline fun Canvas.withClip(
    left: Float,
    top: Float,
    right: Float,
    bottom: Float,
    block: Canvas.() -> Unit
): Unit

Wrap the specified block in calls to Canvas.save/Canvas.clipRect and Canvas.restoreToCount.

withClip

inline fun Canvas.withClip(
    left: Int,
    top: Int,
    right: Int,
    bottom: Int,
    block: Canvas.() -> Unit
): Unit

Wrap the specified block in calls to Canvas.save/Canvas.clipRect and Canvas.restoreToCount.

withMatrix

inline fun Canvas.withMatrix(matrix: Matrix = Matrix(), block: Canvas.() -> Unit): Unit

Wrap the specified block in calls to Canvas.save/Canvas.concat and Canvas.restoreToCount.

withRotation

inline fun Canvas.withRotation(
    degrees: Float = 0.0f,
    pivotX: Float = 0.0f,
    pivotY: Float = 0.0f,
    block: Canvas.() -> Unit
): Unit

Wrap the specified block in calls to Canvas.save/Canvas.rotate and Canvas.restoreToCount.

withSave

inline fun Canvas.withSave(block: Canvas.() -> Unit): Unit

Wrap the specified block in calls to Canvas.save and Canvas.restoreToCount.

withScale

inline fun Canvas.withScale(
    x: Float = 1.0f,
    y: Float = 1.0f,
    pivotX: Float = 0.0f,
    pivotY: Float = 0.0f,
    block: Canvas.() -> Unit
): Unit

Wrap the specified block in calls to Canvas.save/Canvas.scale and Canvas.restoreToCount.

withSkew

inline fun Canvas.withSkew(x: Float = 0.0f, y: Float = 0.0f, block: Canvas.() -> Unit): Unit

Wrap the specified block in calls to Canvas.save/Canvas.skew and Canvas.restoreToCount.

withTranslation

inline fun Canvas.withTranslation(x: Float = 0.0f, y: Float = 0.0f, block: Canvas.() -> Unit): Unit

Wrap the specified block in calls to Canvas.save/Canvas.translate and Canvas.restoreToCount.

xor

inline infix fun Path.xor(p: Path): Path

Returns the union minus the intersection of two paths as a new Path.

xor

inline infix fun Rect.xor(r: Rect): Region

Returns the union minus the intersection of two rectangles as a new region.

xor

inline infix fun Region.xor(r: Rect): Region

Return the union minus the intersection of this region and the specified Rect as a new region.

xor

inline infix fun RectF.xor(r: RectF): Region

Returns the union minus the intersection of two rectangles as a new region. The two rectangles are first converted to Rect using RectF.toRect.

xor

inline infix fun Region.xor(r: Region): Region

Return the union minus the intersection of this region and the specified region as a new region.

Extension properties

alpha

val @ColorInt Int.alphaInt

Return the alpha component of a color int. This is equivalent to calling:

Color.alpha(myInt)

alpha

val @ColorLong Long.alphaFloat

Return the alpha component of a color long. This is equivalent to calling:

Color.alpha(myLong)

blue

val @ColorInt Int.blueInt

Return the blue component of a color int. This is equivalent to calling:

Color.blue(myInt)

blue

val @ColorLong Long.blueFloat

Return the blue component of a color long. This is equivalent to calling:

Color.blue(myLong)

colorSpace

val @ColorLong Long.colorSpaceColorSpace

Returns the color space encoded in the specified color long.

green

val @ColorInt Int.greenInt

Return the green component of a color int. This is equivalent to calling:

Color.green(myInt)

green

val @ColorLong Long.greenFloat

Return the green component of a color long. This is equivalent to calling:

Color.green(myLong)

isSrgb

val @ColorLong Long.isSrgbBoolean

Indicates whether the color is in the sRGB color space.

isWideGamut

val @ColorLong Long.isWideGamutBoolean

Indicates whether the color is in a wide-gamut color space.

luminance

val @ColorInt Int.luminanceFloat

Returns the relative luminance of a color int, assuming sRGB encoding. Based on the formula for relative luminance defined in WCAG 2.0, W3C Recommendation 11 December 2008.

luminance

val @ColorLong Long.luminanceFloat

Returns the relative luminance of a color. Based on the formula for relative luminance defined in WCAG 2.0, W3C Recommendation 11 December 2008.

red

val @ColorInt Int.redInt

Return the red component of a color int. This is equivalent to calling:

Color.red(myInt)

red

val @ColorLong Long.redFloat

Return the red component of a color long. This is equivalent to calling:

Color.red(myLong)