ImageKt

Added in 1.4.0-alpha01

public final class ImageKt


Summary

Public methods

static final @NonNull ResourceBuilders.AndroidImageResourceByResId

Builds image resource that maps to an Android drawable by the given resource ID.

static final @NonNull LayoutElementBuilders.Image
basicImage(
    @NonNull ProtoLayoutScope receiver,
    @NonNull ResourceBuilders.ImageResource resource,
    @NonNull DimensionBuilders.ImageDimension width,
    @NonNull DimensionBuilders.ImageDimension height,
    String protoLayoutResourceId,
    LayoutModifier modifier,
    int contentScaleMode,
    LayoutColor tintColor
)

Builds an image from the given resources.

static final @NonNull ResourceBuilders.ImageResource

Builds a resource object for the image, based on the given resources types.

static final @NonNull ResourceBuilders.InlineImageResource
inlineImageResource(
    @NonNull byte[] compressedBytes,
    @Dimension(unit = 1) int widthPx,
    @Dimension(unit = 1) int heightPx
)

Builds image resource that contains the compressed image data extracted from the raw image data.

static final @NonNull ResourceBuilders.InlineImageResource
inlineImageResource(
    @NonNull byte[] pixelBuffer,
    int format,
    @Dimension(unit = 1) int widthPx,
    @Dimension(unit = 1) int heightPx
)

Builds image resource that contains the pixel buffer in the specified format of the given byte array data.

static final @NonNull ResourceBuilders.AndroidLottieResourceByResId
lottieResource(
    @RawRes int rawResourceId,
    @NonNull DynamicBuilders.DynamicFloat progress,
    @NonNull List<@NonNull ResourceBuilders.LottieProperty> properties
)

Builds Lottie resource that is read from a raw Android resource ID and can be played via progress.

static final @NonNull ResourceBuilders.AndroidLottieResourceByResId
lottieResource(
    @RawRes int rawResourceId,
    TriggerBuilders.Trigger startTrigger,
    @NonNull List<@NonNull ResourceBuilders.LottieProperty> properties
)

Builds Lottie resource that is read from a raw Android resource ID and can be played via starting trigger.

Public methods

androidImageResource

public static final @NonNull ResourceBuilders.AndroidImageResourceByResId androidImageResource(@DrawableRes int resourceId)

Builds image resource that maps to an Android drawable by the given resource ID.

Parameters
@DrawableRes int resourceId

The drawable resource ID to map this image

public static final @NonNull LayoutElementBuilders.Image basicImage(
    @NonNull ProtoLayoutScope receiver,
    @NonNull ResourceBuilders.ImageResource resource,
    @NonNull DimensionBuilders.ImageDimension width,
    @NonNull DimensionBuilders.ImageDimension height,
    String protoLayoutResourceId,
    LayoutModifier modifier,
    int contentScaleMode,
    LayoutColor tintColor
)

Builds an image from the given resources.

Parameters
@NonNull ResourceBuilders.ImageResource resource

An Image resource, used in the layout in the place of this element

@NonNull DimensionBuilders.ImageDimension width

The width of the image

@NonNull DimensionBuilders.ImageDimension height

The height of the image

String protoLayoutResourceId

The optional String ID for the resource. This is optional as it has a default value assigned by the automatic resource registration, but can be used to override it if desired to mark the resource with readable ID.

LayoutModifier modifier

Modifiers to set to this element

int contentScaleMode

Defines how the content which does not match the dimensions of its bounds (e.g. an image resource being drawn inside an Image) will be resized to fit its bounds

LayoutColor tintColor

The tint color to apply to the image

public static final @NonNull ResourceBuilders.ImageResource imageResource(
    ResourceBuilders.AndroidImageResourceByResId androidImage,
    ResourceBuilders.InlineImageResource inlineImage,
    ResourceBuilders.AndroidLottieResourceByResId lottie
)

Builds a resource object for the image, based on the given resources types. This can hold multiple underlying resource types, which the underlying renderer will pick according to what it is supported in its version and what it thinks is appropriate.

It is recommended to use this inside the APIs for the automatic resource registration, such as basicImage.

Parameters
ResourceBuilders.AndroidImageResourceByResId androidImage

The image resource that maps to an Android drawable by resource ID

ResourceBuilders.InlineImageResource inlineImage

The image resource that contains the image data inline

ResourceBuilders.AndroidLottieResourceByResId lottie

The Lottie resource that is read from a raw Android resource ID

inlineImageResource

public static final @NonNull ResourceBuilders.InlineImageResource inlineImageResource(
    @NonNull byte[] compressedBytes,
    @Dimension(unit = 1) int widthPx,
    @Dimension(unit = 1) int heightPx
)

Builds image resource that contains the compressed image data extracted from the raw image data.

This data shouldn't be in any format. If the image data bytes are formatted use inlineImageResource with (ByteArray, Int, Int, Int).

Parameters
@NonNull byte[] compressedBytes

The byte array representing the image

@Dimension(unit = 1) int widthPx

The native width of the image, in pixels.

@Dimension(unit = 1) int heightPx

The native height of the image, in pixels.

inlineImageResource

public static final @NonNull ResourceBuilders.InlineImageResource inlineImageResource(
    @NonNull byte[] pixelBuffer,
    int format,
    @Dimension(unit = 1) int widthPx,
    @Dimension(unit = 1) int heightPx
)

Builds image resource that contains the pixel buffer in the specified format of the given byte array data.

Parameters
@NonNull byte[] pixelBuffer

The byte array representing the image

int format

The format of the byte array data representing the image. This should be specific format of IMAGE_FORMAT_RGB_565 or IMAGE_FORMAT_ARGB_8888. If compressed image data is used, then inlineImageResource with (ByteArray, Int, Int) should be used, without specified format.

@Dimension(unit = 1) int widthPx

The native width of the image, in pixels.

@Dimension(unit = 1) int heightPx

The native height of the image, in pixels.

public static final @NonNull ResourceBuilders.AndroidLottieResourceByResId lottieResource(
    @RawRes int rawResourceId,
    @NonNull DynamicBuilders.DynamicFloat progress,
    @NonNull List<@NonNull ResourceBuilders.LottieProperty> properties
)

Builds Lottie resource that is read from a raw Android resource ID and can be played via progress.

Parameters
@RawRes int rawResourceId

The raw resource ID to map this Lottie

@NonNull DynamicBuilders.DynamicFloat progress

The DynamicFloat, normally transformed from certain states with the data binding pipeline to control the progress of the animation. Its value is required to fall in the range of 0.0, 1.0. Any values outside this range would be clamped.

@NonNull List<@NonNull ResourceBuilders.LottieProperty> properties

The list of properties to customize Lottie further

public static final @NonNull ResourceBuilders.AndroidLottieResourceByResId lottieResource(
    @RawRes int rawResourceId,
    TriggerBuilders.Trigger startTrigger,
    @NonNull List<@NonNull ResourceBuilders.LottieProperty> properties
)

Builds Lottie resource that is read from a raw Android resource ID and can be played via starting trigger.

Parameters
@RawRes int rawResourceId

The raw resource ID to map this Lottie

TriggerBuilders.Trigger startTrigger

The trigger to start the animation. If not set, animation will be played on layout load

@NonNull List<@NonNull ResourceBuilders.LottieProperty> properties

The list of properties to customize Lottie further