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

ImageVector.Builder

public final class ImageVector.Builder


Builder used to construct a Vector graphic tree. This is useful for caching the result of expensive operations used to construct a vector graphic for compose. For example, the vector graphic could be serialized and downloaded from a server and represented internally in a ImageVector before it is composed through rememberVectorPainter The generated ImageVector is recommended to be memoized across composition calls to avoid doing redundant work

Summary

Public constructors

Builder(
    @NonNull String name,
    @NonNull Dp defaultWidth,
    @NonNull Dp defaultHeight,
    float viewportWidth,
    float viewportHeight,
    @NonNull Color tintColor,
    @NonNull BlendMode tintBlendMode,
    boolean autoMirror
)

Public methods

final @NonNull ImageVector.Builder
addGroup(
    @NonNull String name,
    float rotate,
    float pivotX,
    float pivotY,
    float scaleX,
    float scaleY,
    float translationX,
    float translationY,
    @NonNull List<@NonNull PathNode> clipPathData
)

Create a new group and push it to the front of the stack of ImageVector nodes

final @NonNull ImageVector.Builder
addPath(
    @NonNull List<@NonNull PathNode> pathData,
    @NonNull PathFillType pathFillType,
    @NonNull String name,
    Brush fill,
    float fillAlpha,
    Brush stroke,
    float strokeAlpha,
    float strokeLineWidth,
    @NonNull StrokeCap strokeLineCap,
    @NonNull StrokeJoin strokeLineJoin,
    float strokeLineMiter,
    float trimPathStart,
    float trimPathEnd,
    float trimPathOffset
)

Add a path to the ImageVector graphic.

final @NonNull ImageVector

Construct a ImageVector.

final @NonNull ImageVector.Builder

Pops the topmost VectorGroup from this ImageVector.Builder.

Extension functions

final @NonNull ImageVector.Builder
ImageVectorKt.group(
    @NonNull ImageVector.Builder receiver,
    @NonNull String name,
    float rotate,
    float pivotX,
    float pivotY,
    float scaleX,
    float scaleY,
    float translationX,
    float translationY,
    @NonNull List<@NonNull PathNode> clipPathData,
    @ExtensionFunctionType @NonNull Function1<@NonNull ImageVector.BuilderUnit> block
)

DSL extension for adding a VectorGroup to this.

final @NonNull ImageVector.Builder
ImageVectorKt.path(
    @NonNull ImageVector.Builder receiver,
    @NonNull String name,
    Brush fill,
    float fillAlpha,
    Brush stroke,
    float strokeAlpha,
    float strokeLineWidth,
    @NonNull StrokeCap strokeLineCap,
    @NonNull StrokeJoin strokeLineJoin,
    float strokeLineMiter,
    @NonNull PathFillType pathFillType,
    @ExtensionFunctionType @NonNull Function1<@NonNull PathBuilderUnit> pathBuilder
)

DSL extension for adding a VectorPath to this.

Public constructors

Builder

public Builder(
    @NonNull String name,
    @NonNull Dp defaultWidth,
    @NonNull Dp defaultHeight,
    float viewportWidth,
    float viewportHeight,
    @NonNull Color tintColor,
    @NonNull BlendMode tintBlendMode,
    boolean autoMirror
)

Public methods

addGroup

public final @NonNull ImageVector.Builder addGroup(
    @NonNull String name,
    float rotate,
    float pivotX,
    float pivotY,
    float scaleX,
    float scaleY,
    float translationX,
    float translationY,
    @NonNull List<@NonNull PathNode> clipPathData
)

Create a new group and push it to the front of the stack of ImageVector nodes

Parameters
@NonNull String name

the name of the group

float rotate

the rotation of the group in degrees

float pivotX

the x coordinate of the pivot point to rotate or scale the group

float pivotY

the y coordinate of the pivot point to rotate or scale the group

float scaleX

the scale factor in the X-axis to apply to the group

float scaleY

the scale factor in the Y-axis to apply to the group

float translationX

the translation in virtual pixels to apply along the x-axis

float translationY

the translation in virtual pixels to apply along the y-axis

@NonNull List<@NonNull PathNode> clipPathData

the path information used to clip the content within the group

Returns
@NonNull ImageVector.Builder

This ImageVector.Builder instance as a convenience for chaining calls

addPath

public final @NonNull ImageVector.Builder addPath(
    @NonNull List<@NonNull PathNode> pathData,
    @NonNull PathFillType pathFillType,
    @NonNull String name,
    Brush fill,
    float fillAlpha,
    Brush stroke,
    float strokeAlpha,
    float strokeLineWidth,
    @NonNull StrokeCap strokeLineCap,
    @NonNull StrokeJoin strokeLineJoin,
    float strokeLineMiter,
    float trimPathStart,
    float trimPathEnd,
    float trimPathOffset
)

Add a path to the ImageVector graphic. This represents a leaf node in the ImageVector graphics tree structure

Parameters
@NonNull List<@NonNull PathNode> pathData

path information to render the shape of the path

@NonNull PathFillType pathFillType

rule to determine how the interior of the path is to be calculated

@NonNull String name

the name of the path

Brush fill

specifies the Brush used to fill the path

float fillAlpha

the alpha to fill the path

Brush stroke

specifies the Brush used to fill the stroke

float strokeAlpha

the alpha to stroke the path

float strokeLineWidth

the width of the line to stroke the path

@NonNull StrokeCap strokeLineCap

specifies the linecap for a stroked path

@NonNull StrokeJoin strokeLineJoin

specifies the linejoin for a stroked path

float strokeLineMiter

specifies the miter limit for a stroked path

float trimPathStart

specifies the fraction of the path to trim from the start in the range from 0 to 1. Values outside the range will wrap around the length of the path. Default is 0.

float trimPathStart

specifies the fraction of the path to trim from the end in the range from 0 to 1. Values outside the range will wrap around the length of the path. Default is 1.

float trimPathOffset

specifies the fraction to shift the path trim region in the range from 0 to 1. Values outside the range will wrap around the length of the path. Default is 0.

Returns
@NonNull ImageVector.Builder

This ImageVector.Builder instance as a convenience for chaining calls

build

public final @NonNull ImageVector build()

Construct a ImageVector. This concludes the creation process of a ImageVector graphic This builder cannot be re-used to create additional ImageVector instances

Returns
@NonNull ImageVector

The newly created ImageVector instance

clearGroup

public final @NonNull ImageVector.Builder clearGroup()

Pops the topmost VectorGroup from this ImageVector.Builder. This is used to indicate that no additional ImageVector nodes will be added to the current VectorGroup

Returns
@NonNull ImageVector.Builder

This ImageVector.Builder instance as a convenience for chaining calls

Extension functions

ImageVectorKt.group

public final @NonNull ImageVector.Builder ImageVectorKt.group(
    @NonNull ImageVector.Builder receiver,
    @NonNull String name,
    float rotate,
    float pivotX,
    float pivotY,
    float scaleX,
    float scaleY,
    float translationX,
    float translationY,
    @NonNull List<@NonNull PathNode> clipPathData,
    @ExtensionFunctionType @NonNull Function1<@NonNull ImageVector.BuilderUnit> block
)

DSL extension for adding a VectorGroup to this.

See ImageVector.Builder.pushGroup for the corresponding builder function.

Parameters
@NonNull String name

the name of the group

float rotate

the rotation of the group in degrees

float pivotX

the x coordinate of the pivot point to rotate or scale the group

float pivotY

the y coordinate of the pivot point to rotate or scale the group

float scaleX

the scale factor in the X-axis to apply to the group

float scaleY

the scale factor in the Y-axis to apply to the group

float translationX

the translation in virtual pixels to apply along the x-axis

float translationY

the translation in virtual pixels to apply along the y-axis

@NonNull List<@NonNull PathNode> clipPathData

the path information used to clip the content within the group

@ExtensionFunctionType @NonNull Function1<@NonNull ImageVector.BuilderUnit> block

builder lambda to add children to this group

ImageVectorKt.path

public final @NonNull ImageVector.Builder ImageVectorKt.path(
    @NonNull ImageVector.Builder receiver,
    @NonNull String name,
    Brush fill,
    float fillAlpha,
    Brush stroke,
    float strokeAlpha,
    float strokeLineWidth,
    @NonNull StrokeCap strokeLineCap,
    @NonNull StrokeJoin strokeLineJoin,
    float strokeLineMiter,
    @NonNull PathFillType pathFillType,
    @ExtensionFunctionType @NonNull Function1<@NonNull PathBuilderUnit> pathBuilder
)

DSL extension for adding a VectorPath to this.

See ImageVector.Builder.addPath for the corresponding builder function.

Parameters
@NonNull String name

the name for this path

Brush fill

specifies the Brush used to fill the path

float fillAlpha

the alpha to fill the path

Brush stroke

specifies the Brush used to fill the stroke

float strokeAlpha

the alpha to stroke the path

float strokeLineWidth

the width of the line to stroke the path

@NonNull StrokeCap strokeLineCap

specifies the linecap for a stroked path

@NonNull StrokeJoin strokeLineJoin

specifies the linejoin for a stroked path

float strokeLineMiter

specifies the miter limit for a stroked path

@ExtensionFunctionType @NonNull Function1<@NonNull PathBuilderUnit> pathBuilder

PathBuilder lambda for adding PathNodes to this path.