blob: 5fecbf0f70662532c8ebd444bfce89d376cbc3b8 [file] [log] [blame]
<html devsite="true">
<head>
<title>ImageKt</title>
{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %}
{% include "_shared/_reference-head-tags.html" %}
</head>
<body>
<h1>ImageKt</h1>
<p>
<pre>public final class <a href="/reference/androidx/compose/foundation/ImageKt.html">ImageKt</a></pre>
</p>
<hr>
<h2>Summary</h2>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%"><h3>Public methods</h3></th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br><a href="/reference/androidx/compose/foundation/ImageKt.html#Image(androidx.compose.ui.graphics.ImageBitmap,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a>&nbsp;bitmap,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale,<br>&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;alpha,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter<br>)</code></div>
<p>A composable that lays out and draws a given <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code>.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br><a href="/reference/androidx/compose/foundation/ImageKt.html#Image(androidx.compose.ui.graphics.vector.ImageVector,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a>&nbsp;imageVector,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale,<br>&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;alpha,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter<br>)</code></div>
<p>A composable that lays out and draws a given <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code>.</p>
</td>
</tr>
<tr>
<td><code>static&nbsp;final void</code></td>
<td>
<div><code>@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br><a href="/reference/androidx/compose/foundation/ImageKt.html#Image(androidx.compose.ui.graphics.painter.Painter,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a>&nbsp;painter,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale,<br>&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;alpha,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter<br>)</code></div>
<p>Creates a composable that lays out and draws a given <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code>.</p>
</td>
</tr>
</tbody>
</table>
</div>
<div class="list">
<h2>Public methods</h2>
<div class="api-item"><a name="Image(androidx.compose.ui.graphics.ImageBitmap, kotlin.String, androidx.compose.ui.Modifier, androidx.compose.ui.Alignment, androidx.compose.ui.layout.ContentScale, kotlin.Float, androidx.compose.ui.graphics.ColorFilter)"></a><a name="Image-androidx.compose.ui.graphics.ImageBitmap-kotlin.String-androidx.compose.ui.Modifier-androidx.compose.ui.Alignment-androidx.compose.ui.layout.ContentScale-kotlin.Float-androidx.compose.ui.graphics.ColorFilter-"></a><a name="image"></a>
<h3 class="api-name" id="Image(androidx.compose.ui.graphics.ImageBitmap,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/foundation/ImageKt.html#Image(androidx.compose.ui.graphics.ImageBitmap,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a>&nbsp;bitmap,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale,<br>&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;alpha,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter<br>)</pre>
<p>A composable that lays out and draws a given <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code>. This will attempt to size the composable according to the <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code>'s given width and height. However, an optional <code><a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a></code> parameter can be provided to adjust sizing or draw additional content (ex. background). Any unspecified dimension will leverage the <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code>'s size as a minimum constraint.</p>
<p>The following sample shows basic usage of an Image composable to position and draw an <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code> on screen</p>
<pre class="prettyprint">
import androidx.compose.foundation.Image
val ImageBitmap = createTestImage()
// Lays out and draws an image sized to the dimensions of the ImageBitmap
Image(bitmap = ImageBitmap, contentDescription = &quot;Localized description&quot;)</pre>
<p>For use cases that require drawing a rectangular subset of the <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code> consumers can use overload that consumes a <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code> parameter shown in this sample</p>
<pre class="prettyprint">
import androidx.compose.foundation.Image
import androidx.compose.ui.graphics.painter.BitmapPainter
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize
val ImageBitmap = createTestImage()
// Lays out and draws an image sized to the rectangular subsection of the ImageBitmap
Image(
painter = BitmapPainter(
ImageBitmap,
IntOffset(10, 12),
IntSize(50, 60)
),
contentDescription = &quot;Localized description&quot;
)</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a>&nbsp;bitmap</code></td>
<td>
<p>The <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code> to draw</p>
</td>
</tr>
<tr>
<td><code><a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription</code></td>
<td>
<p>text used by accessibility services to describe what this image represents. This should always be provided unless this image is used for decorative purposes, and does not represent a meaningful action that a user can take. This text should be localized, such as by using <code><a href="/reference/androidx/compose/ui/res/package-summary.html#stringResource(kotlin.Int)">androidx.compose.ui.res.stringResource</a></code> or similar</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier</code></td>
<td>
<p>Modifier used to adjust the layout algorithm or draw decoration content (ex. background)</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment</code></td>
<td>
<p>Optional alignment parameter used to place the <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code> in the given bounds defined by the width and height</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale</code></td>
<td>
<p>Optional scale parameter used to determine the aspect ratio scaling to be used if the bounds are a different size from the intrinsic size of the <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code></p>
</td>
</tr>
<tr>
<td><code>float&nbsp;alpha</code></td>
<td>
<p>Optional opacity to be applied to the <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code> when it is rendered onscreen</p>
</td>
</tr>
<tr>
<td><code><a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter</code></td>
<td>
<p>Optional ColorFilter to apply for the <code><a href="/reference/androidx/compose/ui/graphics/ImageBitmap.html">ImageBitmap</a></code> when it is rendered onscreen</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="Image(androidx.compose.ui.graphics.vector.ImageVector, kotlin.String, androidx.compose.ui.Modifier, androidx.compose.ui.Alignment, androidx.compose.ui.layout.ContentScale, kotlin.Float, androidx.compose.ui.graphics.ColorFilter)"></a><a name="Image-androidx.compose.ui.graphics.vector.ImageVector-kotlin.String-androidx.compose.ui.Modifier-androidx.compose.ui.Alignment-androidx.compose.ui.layout.ContentScale-kotlin.Float-androidx.compose.ui.graphics.ColorFilter-"></a><a name="image"></a>
<h3 class="api-name" id="Image(androidx.compose.ui.graphics.vector.ImageVector,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/foundation/ImageKt.html#Image(androidx.compose.ui.graphics.vector.ImageVector,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a>&nbsp;imageVector,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale,<br>&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;alpha,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter<br>)</pre>
<p>A composable that lays out and draws a given <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code>. This will attempt to size the composable according to the <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code>'s given width and height. However, an optional <code><a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a></code> parameter can be provided to adjust sizing or draw additional content (ex. background). Any unspecified dimension will leverage the <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code>'s size as a minimum constraint.</p>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a>&nbsp;imageVector</code></td>
<td>
<p>The <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code> to draw</p>
</td>
</tr>
<tr>
<td><code><a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription</code></td>
<td>
<p>text used by accessibility services to describe what this image represents. This should always be provided unless this image is used for decorative purposes, and does not represent a meaningful action that a user can take. This text should be localized, such as by using <code><a href="/reference/androidx/compose/ui/res/package-summary.html#stringResource(kotlin.Int)">androidx.compose.ui.res.stringResource</a></code> or similar</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier</code></td>
<td>
<p>Modifier used to adjust the layout algorithm or draw decoration content (ex. background)</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment</code></td>
<td>
<p>Optional alignment parameter used to place the <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code> in the given bounds defined by the width and height</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale</code></td>
<td>
<p>Optional scale parameter used to determine the aspect ratio scaling to be used if the bounds are a different size from the intrinsic size of the <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code></p>
</td>
</tr>
<tr>
<td><code>float&nbsp;alpha</code></td>
<td>
<p>Optional opacity to be applied to the <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code> when it is rendered onscreen</p>
</td>
</tr>
<tr>
<td><code><a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter</code></td>
<td>
<p>Optional ColorFilter to apply for the <code><a href="/reference/androidx/compose/ui/graphics/vector/ImageVector.html">ImageVector</a></code> when it is rendered onscreen</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="api-item"><a name="Image(androidx.compose.ui.graphics.painter.Painter, kotlin.String, androidx.compose.ui.Modifier, androidx.compose.ui.Alignment, androidx.compose.ui.layout.ContentScale, kotlin.Float, androidx.compose.ui.graphics.ColorFilter)"></a><a name="Image-androidx.compose.ui.graphics.painter.Painter-kotlin.String-androidx.compose.ui.Modifier-androidx.compose.ui.Alignment-androidx.compose.ui.layout.ContentScale-kotlin.Float-androidx.compose.ui.graphics.ColorFilter-"></a><a name="image"></a>
<h3 class="api-name" id="Image(androidx.compose.ui.graphics.painter.Painter,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</h3>
<pre class="api-signature no-pretty-print">@<a href="/reference/androidx/compose/runtime/Composable.html">Composable</a><br>public&nbsp;static&nbsp;final&nbsp;void&nbsp;<a href="/reference/androidx/compose/foundation/ImageKt.html#Image(androidx.compose.ui.graphics.painter.Painter,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</a>(<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a>&nbsp;painter,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment,<br>&nbsp;&nbsp;&nbsp;&nbsp;@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale,<br>&nbsp;&nbsp;&nbsp;&nbsp;float&nbsp;alpha,<br>&nbsp;&nbsp;&nbsp;&nbsp;<a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter<br>)</pre>
<p>Creates a composable that lays out and draws a given <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code>. This will attempt to size the composable according to the <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code>'s intrinsic size. However, an optional <code><a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a></code> parameter can be provided to adjust sizing or draw additional content (ex. background)</p>
<p><b>NOTE</b> a Painter might not have an intrinsic size, so if no LayoutModifier is provided as part of the Modifier chain this might size the <code><a href="/reference/androidx/compose/foundation/package-summary.html#Image(androidx.compose.ui.graphics.ImageBitmap,kotlin.String,androidx.compose.ui.Modifier,androidx.compose.ui.Alignment,androidx.compose.ui.layout.ContentScale,kotlin.Float,androidx.compose.ui.graphics.ColorFilter)">Image</a></code> composable to a width and height of zero and will not draw any content. This can happen for Painter implementations that always attempt to fill the bounds like <code><a href="/reference/androidx/compose/ui/graphics/painter/ColorPainter.html">ColorPainter</a></code></p>
<pre class="prettyprint">
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.remember
import androidx.compose.ui.geometry.Size
val customPainter = remember {
object : Painter() {
override val intrinsicSize: Size
get() = Size(100.0f, 100.0f)
override fun DrawScope.onDraw() {
drawRect(color = Color.Cyan)
}
}
}
Image(
painter = customPainter,
contentDescription = &quot;Localized description&quot;,
modifier = Modifier.size(100.dp, 100.dp)
)</pre>
<div class="devsite-table-wrapper">
<table class="responsive">
<colgroup>
<col width="40%">
<col>
</colgroup>
<thead>
<tr>
<th colspan="100%">Parameters</th>
</tr>
</thead>
<tbody class="list">
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a>&nbsp;painter</code></td>
<td>
<p>to draw</p>
</td>
</tr>
<tr>
<td><code><a href="https://developer.android.com/reference/java/lang/String.html">String</a>&nbsp;contentDescription</code></td>
<td>
<p>text used by accessibility services to describe what this image represents. This should always be provided unless this image is used for decorative purposes, and does not represent a meaningful action that a user can take. This text should be localized, such as by using <code><a href="/reference/androidx/compose/ui/res/package-summary.html#stringResource(kotlin.Int)">androidx.compose.ui.res.stringResource</a></code> or similar</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Modifier.html">Modifier</a>&nbsp;modifier</code></td>
<td>
<p>Modifier used to adjust the layout algorithm or draw decoration content (ex. background)</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/Alignment.html">Alignment</a>&nbsp;alignment</code></td>
<td>
<p>Optional alignment parameter used to place the <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code> in the given bounds defined by the width and height.</p>
</td>
</tr>
<tr>
<td><code>@<a href="/reference/androidx/annotation/NonNull.html">NonNull</a> <a href="/reference/androidx/compose/ui/layout/ContentScale.html">ContentScale</a>&nbsp;contentScale</code></td>
<td>
<p>Optional scale parameter used to determine the aspect ratio scaling to be used if the bounds are a different size from the intrinsic size of the <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code></p>
</td>
</tr>
<tr>
<td><code>float&nbsp;alpha</code></td>
<td>
<p>Optional opacity to be applied to the <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code> when it is rendered onscreen the default renders the <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code> completely opaque</p>
</td>
</tr>
<tr>
<td><code><a href="/reference/androidx/compose/ui/graphics/ColorFilter.html">ColorFilter</a>&nbsp;colorFilter</code></td>
<td>
<p>Optional colorFilter to apply for the <code><a href="/reference/androidx/compose/ui/graphics/painter/Painter.html">Painter</a></code> when it is rendered onscreen</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</body>
</html>