A composable that lays out and draws a given [ImageBitmap].
BitmapPainterSample
@Composable
fun BitmapPainterSample() {
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 = "Localized description",
modifier = Modifier.size(100.dp, 100.dp),
)
}
BitmapPainterSubsectionSample
@Composable
fun BitmapPainterSubsectionSample() {
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 = "Localized description",
)
}
ImageSample
@Composable
fun ImageSample() {
val ImageBitmap = createTestImage()
// Lays out and draws an image sized to the dimensions of the ImageBitmap
Image(bitmap = ImageBitmap, contentDescription = "Localized description")
}