RemoteBasicImage

Functions summary

Unit
@Composable
@RemoteComposable
RemoteBasicImage(
    bitmap: RemoteImageBitmap,
    contentDescription: RemoteString?,
    modifier: RemoteModifier,
    contentScale: RemoteContentScale,
    alpha: RemoteFloat
)

Lays out and draws a given RemoteImageBitmap in a remote layout.

Functions

@Composable
@RemoteComposable
fun RemoteBasicImage(
    bitmap: RemoteImageBitmap,
    contentDescription: RemoteString?,
    modifier: RemoteModifier = RemoteModifier,
    contentScale: RemoteContentScale = RemoteContentScale.Fit,
    alpha: RemoteFloat = 1f.rf
): Unit

Lays out and draws a given RemoteImageBitmap in a remote layout.

This is the remote equivalent of androidx.compose.foundation.Image. Provide a localized contentDescription (for example, via stringResource) whenever the image conveys meaning; pass null only for purely decorative images so accessibility services ignore them.

Example of a RemoteBasicImage cropped to fill its container:

import androidx.compose.remote.creation.compose.layout.RemoteContentScale
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.state.RemoteImageBitmap
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.remote.foundation.image.RemoteBasicImage
import androidx.compose.runtime.remember
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Paint

val remoteBitmap = remember {
    val imageBitmap = ImageBitmap(120, 60)
    Canvas(imageBitmap).apply {
        drawRect(0f, 0f, 120f, 60f, Paint().apply { color = Color(0xFF1E88E5) })
        drawCircle(Offset(60f, 30f), 20f, Paint().apply { color = Color(0xFFFFCA28) })
    }
    RemoteImageBitmap(imageBitmap)
}
RemoteBasicImage(
    bitmap = remoteBitmap,
    contentDescription = "Sample Image".rs,
    modifier = RemoteModifier.size(100.rdp),
    contentScale = RemoteContentScale.Crop,
)

Example of a RemoteBasicImage scaled with RemoteContentScale.Fit inside its container:

import androidx.compose.remote.creation.compose.layout.RemoteContentScale
import androidx.compose.remote.creation.compose.modifier.RemoteModifier
import androidx.compose.remote.creation.compose.modifier.background
import androidx.compose.remote.creation.compose.modifier.size
import androidx.compose.remote.creation.compose.state.RemoteImageBitmap
import androidx.compose.remote.creation.compose.state.rc
import androidx.compose.remote.creation.compose.state.rdp
import androidx.compose.remote.creation.compose.state.rs
import androidx.compose.remote.foundation.image.RemoteBasicImage
import androidx.compose.runtime.remember
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Canvas
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Paint

val remoteBitmap = remember {
    val imageBitmap = ImageBitmap(120, 60)
    Canvas(imageBitmap).apply {
        drawRect(0f, 0f, 120f, 60f, Paint().apply { color = Color(0xFF1E88E5) })
        drawCircle(Offset(60f, 30f), 20f, Paint().apply { color = Color(0xFFFFCA28) })
    }
    RemoteImageBitmap(imageBitmap)
}
RemoteBasicImage(
    bitmap = remoteBitmap,
    contentDescription = "Sample Image Fit".rs,
    modifier = RemoteModifier.size(100.rdp).background(Color.LightGray.rc),
    contentScale = RemoteContentScale.Fit,
)
Parameters
bitmap: RemoteImageBitmap

the RemoteImageBitmap to draw

contentDescription: RemoteString?

localized text used by accessibility services to describe what this image represents, or null if the image is purely decorative and should be ignored by accessibility services

modifier: RemoteModifier = RemoteModifier

the RemoteModifier applied to this layout node

contentScale: RemoteContentScale = RemoteContentScale.Fit

rule applied to scale the image when its layout bounds differ from the intrinsic size of bitmap. Defaults to RemoteContentScale.Fit

alpha: RemoteFloat = 1f.rf

opacity applied to bitmap when rendered, from 0.0f (transparent) to 1.0f (opaque). Defaults to 1.0f