androidx.compose.foundation

Image

Composable function · from org.jetbrains.compose.foundation:foundation:1.12.2

Image shows a picture in its original colors. Most often you pass a painter from painterResource(Res.drawable.photo); see the Images and resources guide.

Image(
    painter = painterResource(Res.drawable.landscape),
    contentDescription = "Hills at sunset",
    contentScale = ContentScale.Crop,
    modifier = Modifier.size(200.dp).clip(MaterialTheme.shapes.large),
)

For one-color icons that follow the theme, use Icon instead. It tints the picture with the content color.

To load pictures from the internet, use an image loading library, like Coil. Compose has no built-in network loading.

Bitmap

An ImageBitmap, like a decoded photo.

@Composable
fun Image(
    bitmap: ImageBitmap,
    contentDescription: String?,
    modifier: Modifier = Modifier,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Fit,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
    filterQuality: FilterQuality = DefaultFilterQuality,
)

bitmap: ImageBitmapRequired

A decoded picture. Get one with imageResource(...), or decode bytes with decodeToImageBitmap().

contentDescription: String?Required

What the picture shows, for screen readers. Pass null if it is only decoration.

modifier: ModifierOptional

Default: Modifier

Changes size, padding, or position. See the Modifier guide.

alignment: AlignmentOptional

Default: Alignment.Center

Where the picture goes when it doesn't fill the area. Default: centered.

contentScale: ContentScaleOptional

Default: ContentScale.Fit

How the picture fits the area: Fit shows all of it, Crop fills the area and cuts off the rest, FillBounds stretches it. See the Images and resources guide.

alpha: FloatOptional

Default: DefaultAlpha

How see-through it is, from 0 (invisible) to 1 (solid).

colorFilter: ColorFilter?Optional

Default: null

Changes the colors when drawing. ColorFilter.tint(color) paints it in one color.

filterQuality: FilterQualityOptional

Default: DefaultFilterQuality

How smooth the picture is when scaled. Use FilterQuality.None for sharp pixel art.

Vector

An ImageVector, like Icons.Filled.Home.

@Composable
fun Image(
    imageVector: ImageVector,
    contentDescription: String?,
    modifier: Modifier = Modifier,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Fit,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
)

imageVector: ImageVectorRequired

A vector picture, like Icons.Filled.Star or vectorResource(...).

Same as above: contentDescription, modifier, alignment, contentScale, alpha, colorFilter.

Painter

Anything that can draw itself, like painterResource(...).

@Composable
fun Image(
    painter: Painter,
    contentDescription: String?,
    modifier: Modifier = Modifier,
    alignment: Alignment = Alignment.Center,
    contentScale: ContentScale = ContentScale.Fit,
    alpha: Float = DefaultAlpha,
    colorFilter: ColorFilter? = null,
)

painter: PainterRequired

Anything that draws a picture. Usually painterResource(...).

Same as above: contentDescription, modifier, alignment, contentScale, alpha, colorFilter.