# ImageKt

Added in 1.4.2

*** ** * ** ***


```
public final class ImageKt
```

<br />

*** ** * ** ***

## Summary

| ### Public methods |
|---|---|
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.AndroidImageResourceByResId` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/ImageKt#androidImageResource(kotlin.Int)(@https://developer.android.com/reference/androidx/annotation/DrawableRes int resourceId)` Builds image resource that maps to an Android drawable by the given resource ID. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/LayoutElementBuilders.Image` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/ImageKt#(androidx.wear.protolayout.ProtoLayoutScope).basicImage(androidx.wear.protolayout.ResourceBuilders.ImageResource,androidx.wear.protolayout.DimensionBuilders.ImageDimension,androidx.wear.protolayout.DimensionBuilders.ImageDimension,kotlin.String,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ProtoLayoutScope receiver, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.ImageResource resource, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ImageDimension width, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ImageDimension height, https://developer.android.com/reference/java/lang/String.html protoLayoutResourceId, https://developer.android.com/reference/androidx/wear/protolayout/modifiers/LayoutModifier modifier, int contentScaleMode, https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutColor tintColor )` Builds an image from the given resources. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.ImageResource` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/ImageKt#imageResource(androidx.wear.protolayout.ResourceBuilders.AndroidImageResourceByResId,androidx.wear.protolayout.ResourceBuilders.InlineImageResource,androidx.wear.protolayout.ResourceBuilders.AndroidLottieResourceByResId)( https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.AndroidImageResourceByResId androidImage, https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.InlineImageResource inlineImage, https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.AndroidLottieResourceByResId lottie )` Builds a resource object for the image, based on the given resources types. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.InlineImageResource` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/ImageKt#inlineImageResource(kotlin.ByteArray,kotlin.Int,kotlin.Int)( @https://developer.android.com/reference/androidx/annotation/NonNull byte[] compressedBytes, @https://developer.android.com/reference/androidx/annotation/Dimension(unit = 1) int widthPx, @https://developer.android.com/reference/androidx/annotation/Dimension(unit = 1) int heightPx )` Builds image resource that contains the compressed image data extracted from the raw image data. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.InlineImageResource` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/ImageKt#inlineImageResource(kotlin.ByteArray,kotlin.Int,kotlin.Int,kotlin.Int)( @https://developer.android.com/reference/androidx/annotation/NonNull byte[] pixelBuffer, int format, @https://developer.android.com/reference/androidx/annotation/Dimension(unit = 1) int widthPx, @https://developer.android.com/reference/androidx/annotation/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 @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.AndroidLottieResourceByResId` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/ImageKt#lottieResource(kotlin.Int,androidx.wear.protolayout.expression.DynamicBuilders.DynamicFloat,kotlin.collections.List)( @https://developer.android.com/reference/androidx/annotation/RawRes int rawResourceId, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicFloat progress, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.LottieProperty> properties )` Builds Lottie resource that is read from a raw Android resource ID and can be played via progress. |
| `static final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.AndroidLottieResourceByResId` | `https://developer.android.com/reference/androidx/wear/protolayout/layout/ImageKt#lottieResource(kotlin.Int,androidx.wear.protolayout.TriggerBuilders.Trigger,kotlin.collections.List)( @https://developer.android.com/reference/androidx/annotation/RawRes int rawResourceId, https://developer.android.com/reference/androidx/wear/protolayout/TriggerBuilders.Trigger startTrigger, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/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

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/layout/Image.kt+function:androidImageResource) Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/DrawableRes int resourceId` | The drawable resource ID to map this image |

### basicImage

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/layout/Image.kt+function:basicImage) Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.ImageResource resource` | An Image resource, used in the layout in the place of this element |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ImageDimension width` | The width of the image |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/DimensionBuilders.ImageDimension height` | The height of the image |
| `https://developer.android.com/reference/java/lang/String.html 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. |
| `https://developer.android.com/reference/androidx/wear/protolayout/modifiers/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 |
| `https://developer.android.com/reference/androidx/wear/protolayout/types/LayoutColor tintColor` | The tint color to apply to the image |

### imageResource

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/layout/Image.kt+function:imageResource) Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
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 `https://developer.android.com/reference/androidx/wear/protolayout/layout/package-summary#(androidx.wear.protolayout.ProtoLayoutScope).basicImage(androidx.wear.protolayout.ResourceBuilders.ImageResource,androidx.wear.protolayout.DimensionBuilders.ImageDimension,androidx.wear.protolayout.DimensionBuilders.ImageDimension,kotlin.String,androidx.wear.protolayout.modifiers.LayoutModifier,kotlin.Int,androidx.wear.protolayout.types.LayoutColor)`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.AndroidImageResourceByResId androidImage` | The image resource that maps to an Android drawable by resource ID |
| `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.InlineImageResource inlineImage` | The image resource that contains the image data inline |
| `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.AndroidLottieResourceByResId lottie` | The Lottie resource that is read from a raw Android resource ID |

### inlineImageResource

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/layout/Image.kt+function:inlineImageResource) Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
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 `https://developer.android.com/reference/androidx/wear/protolayout/layout/package-summary#inlineImageResource(kotlin.ByteArray,kotlin.Int,kotlin.Int)` with `(ByteArray, Int, Int, Int)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull byte[] compressedBytes` | The byte array representing the image |
| `@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 1) int widthPx` | The native width of the image, in pixels. |
| `@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 1) int heightPx` | The native height of the image, in pixels. |

### inlineImageResource

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/layout/Image.kt+function:inlineImageResource) Added in [1.4.2](https://developer.android.com/jetpack/androidx/releases/wear-protolayout#1.4.2)

```
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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/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 `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders#IMAGE_FORMAT_RGB_565()` or `https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders#IMAGE_FORMAT_ARGB_8888()`. If compressed image data is used, then `https://developer.android.com/reference/androidx/wear/protolayout/layout/package-summary#inlineImageResource(kotlin.ByteArray,kotlin.Int,kotlin.Int,kotlin.Int)` with `(ByteArray, Int, Int)` should be used, without specified format. |
| `@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 1) int widthPx` | The native width of the image, in pixels. |
| `@https://developer.android.com/reference/androidx/annotation/Dimension(unit = 1) int heightPx` | The native height of the image, in pixels. |

### lottieResource

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/layout/Image.kt+function:lottieResource)

```
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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/RawRes int rawResourceId` | The raw resource ID to map this Lottie |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/expression/DynamicBuilders.DynamicFloat progress` | The `https://developer.android.com/reference/androidx/wear/protolayout/expression/DynamicBuilders.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. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.LottieProperty> properties` | The list of properties to customize Lottie further |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the number of properties is larger than AndroidLottieResourceByResId.getMaxPropertiesCount() |

### lottieResource

Artifact: [androidx.wear.protolayout:protolayout](https://developer.android.com/jetpack/androidx/releases/wear-protolayout) [View Source](https://cs.android.com/search?q=file:androidx/wear/protolayout/layout/Image.kt+function:lottieResource)

```
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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/RawRes int rawResourceId` | The raw resource ID to map this Lottie |
| `https://developer.android.com/reference/androidx/wear/protolayout/TriggerBuilders.Trigger startTrigger` | The trigger to start the animation. If not set, animation will be played on layout load |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/protolayout/ResourceBuilders.LottieProperty> properties` | The list of properties to customize Lottie further |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-argument-exception/index.html` | if the number of properties is larger than AndroidLottieResourceByResId.getMaxPropertiesCount() |