lightbulb_outline Please take our October 2018 developer survey. Start survey

androidx.core.graphics

Classes

BitmapCompat

Helper for accessing features in android.graphics.Bitmap.

ColorUtils

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

PaintCompat

Helper for accessing features in Paint.

PathSegment

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

PathUtils

A set of path-related utility methods.

Top-level functions summary

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

Returns a mutable bitmap with the specified width and height.

Bitmap
createBitmap(width: Int, height: Int, config: Config = Bitmap.Config.ARGB_8888, hasAlpha: Boolean = true, colorSpace: ColorSpace = ColorSpace.get(ColorSpace.Named.SRGB))

Returns a mutable bitmap with the specified width and height.

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

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 = 1.0f, sy: Float = 1.0f)

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

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

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

Extension functions summary

For android.graphics.Bitmap
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.

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

Returns the value of the pixel at the specified location.

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

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

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

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

For android.graphics.Canvas
Unit
Canvas.withSave(block: Canvas.() -> Unit)

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

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

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

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

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

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

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

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

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

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

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

For android.graphics.Color
operator Float

Returns the first component of the color.

operator Float

Returns the second component of the color.

operator Float

Returns the third component of the color.

operator Float

Returns the fourth component of the color.

operator Color

Composites two translucent colors together.

For kotlin.Int
operator Int

Return the alpha component of a color int.

operator Int

Return the red component of a color int.

operator Int

Return the green component of a color int.

operator Int

Return the blue component of a color int.

Color

Creates a new Color instance from a color int.

Long

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

For kotlin.Long
operator Float

Returns the first component of the color.

operator Float

Returns the second component of the color.

operator Float

Returns the third component of the color.

operator Float

Returns the fourth component of the color.

Color

Creates a new Color instance from a color long.

Int

Converts the specified color long to an ARGB color int.

For android.graphics.Point
operator Int

Returns the x coordinate of this point.

operator Int

Returns the y coordinate of this point.

operator Point

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

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.

operator Point

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

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.

operator Point

Returns a new point representing the negation of this point.

PointF

Returns a PointF representation of this point.

For android.graphics.PointF
operator Float

Returns the x coordinate of this point.

operator Float

Returns the y coordinate of this point.

operator PointF

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

operator PointF

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

operator PointF

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

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.

operator PointF

Returns a new point representing the negation of this point.

Point

Returns a Point representation of this point.

For android.graphics.Rect
operator Int

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

operator Int

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

operator Int

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

operator Int

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

operator Rect

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

operator Rect
Rect.plus(xy: Int)

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

operator Rect

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

operator Region

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

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.

operator Rect

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

infix Rect

Returns the union of two rectangles as a new rectangle.

infix Rect
Rect.or(r: Rect)

Returns the intersection of two rectangles as a new rectangle.

infix Region

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

operator Boolean

Returns true if the specified point is inside the rectangle.

RectF

Returns a RectF representation of this rectangle.

Region

Returns a Region representation of this rectangle.

For android.graphics.RectF
operator Float

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

operator Float

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

operator Float

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

operator Float

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

operator RectF

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

operator RectF

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

operator RectF

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

operator Region

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

operator RectF

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

operator RectF

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

infix RectF

Returns the union of two rectangles as a new rectangle.

infix RectF

Returns the intersection of two rectangles as a new rectangle.

infix Region

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

operator Boolean

Returns true if the specified point is inside the rectangle.

Rect

Returns a Rect representation of this rectangle.

Region

Returns a Region representation of this rectangle.

RectF

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

For android.graphics.Path
operator Path

Returns the union of two paths as a new Path.

Iterable<PathSegment>
Path.flatten(error: Float = 0.5f)

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

operator Path

Returns the difference of two paths as a new Path.

infix Path

Returns the union of two paths as a new Path.

infix Path
Path.or(p: Path)

Returns the intersection of two paths as a new Path.

infix Path

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

For android.graphics.Region
operator Region

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

operator Region

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

operator Region

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

operator Region

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

infix Region

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

infix Region

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

infix Region

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

infix Region

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

infix Region

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

infix Region

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

operator Region

Returns the negation of this region as a new region.

operator Boolean

Return true if the region contains the specified Point.

operator Region

Returns the negation of this region as a new region.

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

Performs the given action on each rect in this region.

operator Iterator<Rect>

Returns an Iterator over the rects in this region.

For kotlin.String
Int

Return a corresponding Int color of this String.

For android.graphics.Matrix
operator Matrix

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

FloatArray

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

For android.graphics.Picture
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.

For android.graphics.PorterDuff.Mode
PorterDuffXfermode

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

PorterDuffColorFilter

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

For android.graphics.Shader
Unit
Shader.transform(block: Matrix.() -> Unit)

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

Extension properties summary

For kotlin.Int
Int

Return the alpha component of a color int.

Int

Return the red component of a color int.

Int

Return the green component of a color int.

Int

Return the blue component of a color int.

Float

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

For kotlin.Long
Float

Return the alpha component of a color long.

Float

Return the red component of a color long.

Float

Return the green component of a color long.

Float

Return the blue component of a color long.

Float

Returns the relative luminance of a color.

Boolean

Indicates whether the color is in the sRGB color space.

Boolean

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

ColorSpace

Returns the color space encoded in the specified color long.

Top-level functions

createBitmap

inline fun createBitmap(width: Int, height: Int, config: 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 The new bitmap's desired width
height The new bitmap's desired height
config The new bitmap's desired config
Return
A new bitmap with the specified dimensions and config

createBitmap

inline fun createBitmap(width: Int, height: Int, config: 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 The new bitmap's desired width
height The new bitmap's desired height
config The new bitmap's desired config
hasAlpha Whether the new bitmap is opaque or not
colorSpace The new bitmap's color space
Return
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 Rect.and(r: Rect): Rect

Returns the union of two rectangles as a new rectangle.

and

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

Returns the union of two rectangles as a new rectangle.

and

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

Returns the union of two paths as a new Path.

and

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

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

and

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

Return the union 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

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

inline operator fun 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

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

inline operator fun 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

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

inline operator fun 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

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

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

contains

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

Return true if the region contains the specified Point.

flatten

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

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

Parameters
error The acceptable error for a line on the Path. 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

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 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 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 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 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 Rect.minus(r: Rect): Region

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

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(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 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 RectF.minus(xy: PointF): RectF

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

minus

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

Returns the difference of two paths as a new Path.

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 Region.minus(r: Region): Region

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

not

inline operator fun Region.not(): Region

Returns the negation of this region as a new region.

or

inline infix fun Rect.or(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.

or

inline infix fun RectF.or(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.

or

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

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

or

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

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

or

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

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

plus

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)
Exceptions
IllegalArgumentException if the color models of the colors do not match

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 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 PointF.plus(p: PointF): PointF

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

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 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 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(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 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 RectF.plus(xy: PointF): RectF

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

plus

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

Returns the union of two paths as a new Path.

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 Region.plus(r: Region): Region

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

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 The new bitmap's desired width
height The new bitmap's desired height
filter true if the source should be filtered (true by default)
Return
The new scaled bitmap or the source bitmap if no scaling is required.

set

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

times

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

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

toColor

inline fun Int.toColor(): Color

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

toColor

inline fun Long.toColor(): Color

Creates a new Color instance from a color long.

toColorFilter

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

inline fun Long.toColorInt(): Int

Converts the specified color long to an ARGB color int.

toColorInt

inline fun String.toColorInt(): 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".

Exceptions
IllegalArgumentException if this String cannot be parsed.

toColorLong

inline fun Int.toColorLong(): 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 Mode.toXfermode(): PorterDuffXfermode

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

transform

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

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

transform

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

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

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.

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 Rect.xor(r: Rect): Region

Returns the union minus the intersection of two rectangles 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 Path.xor(p: Path): Path

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

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

inline val Int.alpha: Int

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


Color.alpha(myInt)

alpha

inline val Long.alpha: Float

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


Color.alpha(myLong)

blue

inline val Int.blue: Int

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


Color.blue(myInt)

blue

inline val Long.blue: Float

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


Color.blue(myLong)

colorSpace

inline val Long.colorSpace: ColorSpace

Returns the color space encoded in the specified color long.

green

inline val Int.green: Int

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


Color.green(myInt)

green

inline val Long.green: Float

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


Color.green(myLong)

isSrgb

inline val Long.isSrgb: Boolean

Indicates whether the color is in the sRGB color space.

isWideGamut

inline val Long.isWideGamut: Boolean

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

luminance

inline val Int.luminance: Float

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

inline val Long.luminance: Float

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

inline val Int.red: Int

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


Color.red(myInt)

red

inline val Long.red: Float

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


Color.red(myLong)