{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

CanvasDrawScope

public final class CanvasDrawScope implements DrawScope


Implementation of DrawScope that issues drawing commands into the specified canvas and bounds via CanvasDrawScope.draw

Summary

Public constructors

Public methods

final void
draw(
    @NonNull Density density,
    @NonNull LayoutDirection layoutDirection,
    @NonNull Canvas canvas,
    @NonNull Size size,
    @ExtensionFunctionType @NonNull Function1<@NonNull DrawScopeUnit> block
)

Draws into the provided Canvas with the commands specified in the lambda with this DrawScope as a receiver

void
drawArc(
    @NonNull Brush brush,
    float startAngle,
    float sweepAngle,
    boolean useCenter,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawArc(
    @NonNull Color color,
    float startAngle,
    float sweepAngle,
    boolean useCenter,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawCircle(
    @NonNull Brush brush,
    float radius,
    @NonNull Offset center,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawCircle(
    @NonNull Color color,
    float radius,
    @NonNull Offset center,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawImage(
    @NonNull ImageBitmap image,
    @NonNull Offset topLeft,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawImage(
    @NonNull ImageBitmap image,
    @NonNull IntOffset srcOffset,
    @NonNull IntSize srcSize,
    @NonNull IntOffset dstOffset,
    @NonNull IntSize dstSize,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode,
    @NonNull FilterQuality filterQuality
)
void
drawLine(
    @NonNull Brush brush,
    @NonNull Offset start,
    @NonNull Offset end,
    float strokeWidth,
    @NonNull StrokeCap cap,
    PathEffect pathEffect,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawLine(
    @NonNull Color color,
    @NonNull Offset start,
    @NonNull Offset end,
    float strokeWidth,
    @NonNull StrokeCap cap,
    PathEffect pathEffect,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawOval(
    @NonNull Brush brush,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawOval(
    @NonNull Color color,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawPath(
    @NonNull Path path,
    @NonNull Brush brush,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawPath(
    @NonNull Path path,
    @NonNull Color color,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawPoints(
    @NonNull List<@NonNull Offset> points,
    @NonNull PointMode pointMode,
    @NonNull Brush brush,
    float strokeWidth,
    @NonNull StrokeCap cap,
    PathEffect pathEffect,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawPoints(
    @NonNull List<@NonNull Offset> points,
    @NonNull PointMode pointMode,
    @NonNull Color color,
    float strokeWidth,
    @NonNull StrokeCap cap,
    PathEffect pathEffect,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawRect(
    @NonNull Brush brush,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawRect(
    @NonNull Color color,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawRoundRect(
    @NonNull Brush brush,
    @NonNull Offset topLeft,
    @NonNull Size size,
    @NonNull CornerRadius cornerRadius,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
void
drawRoundRect(
    @NonNull Color color,
    @NonNull Offset topLeft,
    @NonNull Size size,
    @NonNull CornerRadius cornerRadius,
    @NonNull DrawStyle style,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
float

The logical density of the display.

@NonNull DrawContext

The current DrawContext that contains the dependencies needed to create the drawing environment

float

Current user preference for the scaling factor for fonts.

@NonNull LayoutDirection

The layout direction of the layout being drawn in.

Inherited methods

From androidx.compose.ui.unit.Density
int

Convert Dp to Int by rounding

int

Convert Sp to Int by rounding

@NonNull Dp

Convert Sp to Dp.

@NonNull Dp
orgKt.toDp(int receiver)

Convert an Int pixel value to Dp.

@NonNull Dp
orgKt.toDp(float receiver)

Convert a Float pixel value to a Dp

@NonNull DpSize

Convert a Size to a DpSize.

float
orgKt.toPx(@NonNull Dp receiver)

Convert Dp to pixels.

float

Convert Sp to pixels.

@NonNull Rect

Convert a DpRect to a Rect.

@NonNull Size

Convert a DpSize to a Size.

@NonNull TextUnit
orgKt.toSp(@NonNull Dp receiver)

Convert Dp to Sp.

@NonNull TextUnit
orgKt.toSp(int receiver)

Convert an Int pixel value to Sp.

@NonNull TextUnit
orgKt.toSp(float receiver)

Convert a Float pixel value to a Sp

From androidx.compose.ui.graphics.drawscope.DrawScope
@NonNull Offset

Center of the current bounds of the drawing environment

@NonNull Size

Provides the dimensions of the current drawing environment

Public constructors

CanvasDrawScope

public CanvasDrawScope()

Public methods

draw

public final void draw(
    @NonNull Density density,
    @NonNull LayoutDirection layoutDirection,
    @NonNull Canvas canvas,
    @NonNull Size size,
    @ExtensionFunctionType @NonNull Function1<@NonNull DrawScopeUnit> block
)

Draws into the provided Canvas with the commands specified in the lambda with this DrawScope as a receiver

Parameters
@NonNull Canvas canvas

target canvas to render into

@NonNull Size size

bounds relative to the current canvas translation in which the DrawScope should draw within

@ExtensionFunctionType @NonNull Function1<@NonNull DrawScopeUnit> block

lambda that is called to issue drawing commands on this DrawScope

drawArc

public void drawArc(
    @NonNull Brush brush,
    float startAngle,
    float sweepAngle,
    boolean useCenter,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawArc

drawArc

public void drawArc(
    @NonNull Color color,
    float startAngle,
    float sweepAngle,
    boolean useCenter,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawArc

drawCircle

public void drawCircle(
    @NonNull Brush brush,
    float radius,
    @NonNull Offset center,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawCircle

drawCircle

public void drawCircle(
    @NonNull Color color,
    float radius,
    @NonNull Offset center,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawCircle

drawImage

public void drawImage(
    @NonNull ImageBitmap image,
    @NonNull Offset topLeft,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawImage

drawImage

public void drawImage(
    @NonNull ImageBitmap image,
    @NonNull IntOffset srcOffset,
    @NonNull IntSize srcSize,
    @NonNull IntOffset dstOffset,
    @NonNull IntSize dstSize,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode,
    @NonNull FilterQuality filterQuality
)
See also
drawImage

drawLine

public void drawLine(
    @NonNull Brush brush,
    @NonNull Offset start,
    @NonNull Offset end,
    float strokeWidth,
    @NonNull StrokeCap cap,
    PathEffect pathEffect,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawLine

drawLine

public void drawLine(
    @NonNull Color color,
    @NonNull Offset start,
    @NonNull Offset end,
    float strokeWidth,
    @NonNull StrokeCap cap,
    PathEffect pathEffect,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawLine

drawOval

public void drawOval(
    @NonNull Brush brush,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawOval

drawOval

public void drawOval(
    @NonNull Color color,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawOval

drawPath

public void drawPath(
    @NonNull Path path,
    @NonNull Brush brush,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawPath

drawPath

public void drawPath(
    @NonNull Path path,
    @NonNull Color color,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawPath

drawPoints

public void drawPoints(
    @NonNull List<@NonNull Offset> points,
    @NonNull PointMode pointMode,
    @NonNull Brush brush,
    float strokeWidth,
    @NonNull StrokeCap cap,
    PathEffect pathEffect,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawPoints

drawPoints

public void drawPoints(
    @NonNull List<@NonNull Offset> points,
    @NonNull PointMode pointMode,
    @NonNull Color color,
    float strokeWidth,
    @NonNull StrokeCap cap,
    PathEffect pathEffect,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawPoints

drawRect

public void drawRect(
    @NonNull Brush brush,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawRect

drawRect

public void drawRect(
    @NonNull Color color,
    @NonNull Offset topLeft,
    @NonNull Size size,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawRect

drawRoundRect

public void drawRoundRect(
    @NonNull Brush brush,
    @NonNull Offset topLeft,
    @NonNull Size size,
    @NonNull CornerRadius cornerRadius,
    float alpha,
    @NonNull DrawStyle style,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawRoundRect

drawRoundRect

public void drawRoundRect(
    @NonNull Color color,
    @NonNull Offset topLeft,
    @NonNull Size size,
    @NonNull CornerRadius cornerRadius,
    @NonNull DrawStyle style,
    float alpha,
    ColorFilter colorFilter,
    @NonNull BlendMode blendMode
)
See also
drawRoundRect

getDensity

public float getDensity()

The logical density of the display. This is a scaling factor for the Dp unit.

getDrawContext

public @NonNull DrawContext getDrawContext()

The current DrawContext that contains the dependencies needed to create the drawing environment

getFontScale

public float getFontScale()

Current user preference for the scaling factor for fonts.

getLayoutDirection

public @NonNull LayoutDirection getLayoutDirection()

The layout direction of the layout being drawn in.