Known direct subclasses
BitmapPainter

Painter implementation used to draw an ImageBitmap into the provided canvas This implementation can handle applying alpha and ColorFilter to it's drawn result

BrushPainter

Painter implementation used to fill the provided bounds with the specified Brush.

ColorPainter

Painter implementation used to fill the provided bounds with the specified color

VectorPainter

Painter implementation that abstracts the drawing of a Vector graphic.


Abstraction for something that can be drawn. In addition to providing the ability to draw into a specified bounded area, Painter provides a few high level mechanisms that consumers can use to configure how the content is drawn. These include alpha, ColorFilter, and RTL

Implementations should provide a meaningful equals method that compares values of different Painter subclasses and not rely on just referential equality

Summary

Public constructors

Cmn

Public functions

Unit
DrawScope.draw(size: Size, alpha: Float, colorFilter: ColorFilter?)
Cmn

Protected functions

open Boolean
applyAlpha(alpha: Float)

Apply the provided alpha value returning true if it was applied successfully, or false if it could not be applied

Cmn
open Boolean

Apply the provided color filter returning true if it was applied successfully, or false if it could not be applied

Cmn
open Boolean

Apply the appropriate internal configuration to positioning content with the given LayoutDirection

Cmn
abstract Unit

Implementation of drawing logic for instances of Painter.

Cmn

Public properties

abstract Size

Return the intrinsic size of the Painter.

Cmn

Extension functions

Image
Painter.asAwtImage(
    density: Density,
    layoutDirection: LayoutDirection,
    size: Size
)

This function is deprecated. Use toAwtImage

android
Image
Painter.toAwtImage(
    density: Density,
    layoutDirection: LayoutDirection,
    size: Size
)

Convert Compose Painter to AWT Image.

android

Public constructors

Painter

Painter()

Public functions

fun DrawScope.draw(
    size: Size,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null
): Unit

Protected functions

applyAlpha

protected open fun applyAlpha(alpha: Float): Boolean

Apply the provided alpha value returning true if it was applied successfully, or false if it could not be applied

applyColorFilter

protected open fun applyColorFilter(colorFilter: ColorFilter?): Boolean

Apply the provided color filter returning true if it was applied successfully, or false if it could not be applied

applyLayoutDirection

protected open fun applyLayoutDirection(layoutDirection: LayoutDirection): Boolean

Apply the appropriate internal configuration to positioning content with the given LayoutDirection

onDraw

protected abstract fun DrawScope.onDraw(): Unit

Implementation of drawing logic for instances of Painter. This is invoked internally within draw after the positioning and configuring the Painter

Public properties

intrinsicSize

abstract val intrinsicSizeSize

Return the intrinsic size of the Painter. If the there is no intrinsic size (i.e. filling bounds with an arbitrary color) return Size.Unspecified. If there is no intrinsic size in a single dimension, return Size with Float.NaN in the desired dimension. If a Painter does not have an intrinsic size, it will always draw within the full bounds of the destination

Extension functions

asAwtImage

fun Painter.asAwtImage(
    density: Density,
    layoutDirection: LayoutDirection,
    size: Size = intrinsicSize
): Image

Convert Compose Painter to AWT Image. The result will not be rasterized right now, it will be rasterized when AWT will request the image with needed width and height, by calling AbstractMultiResolutionImage.getResolutionVariant on Windows/Linux, or AbstractMultiResolutionImage.getResolutionVariants on macOs.

At the rasterization moment, density and layoutDirection will be passed to the painter. Usually most painters don't use them. Like the painters for svg/xml/raster resources: they don't use absolute '.dp' values to draw, they use values which are relative to their viewport.

density also will be used to rasterize the default image, which can be used by some implementations (Tray icon on macOs, disabled icon for menu items)

Parameters
density: Density

density will be used to convert dp units

layoutDirection: LayoutDirection

direction for layout when drawing

size: Size = intrinsicSize

the size of the Image

toAwtImage

fun Painter.toAwtImage(
    density: Density,
    layoutDirection: LayoutDirection,
    size: Size = intrinsicSize
): Image

Convert Compose Painter to AWT Image. The result will not be rasterized right now, it will be rasterized when AWT will request the image with needed width and height, by calling AbstractMultiResolutionImage.getResolutionVariant on Windows/Linux, or AbstractMultiResolutionImage.getResolutionVariants on macOs.

At the rasterization moment, density and layoutDirection will be passed to the painter. Usually most painters don't use them. Like the painters for svg/xml/raster resources: they don't use absolute '.dp' values to draw, they use values which are relative to their viewport.

Parameters
density: Density

density will be used to convert dp units when drawing

layoutDirection: LayoutDirection

direction for layout when drawing

size: Size = intrinsicSize

the size of the Image