#Compose 中的 Image
Compose的 "Image" 就是 Image 函式,那就來看看有什麼可以運用的吧
Image(
painter = painterResource(id = R.drawable.android_developers),
contentDescription = "android_developers",
modifier = Modifier.fillMaxWidth()
)
Image(
painter: Painter,
contentDescription: String?,
modifier: Modifier = Modifier,
alignment: Alignment = Alignment.Center,
contentScale: ContentScale = ContentScale.Fit,
alpha: Float = DefaultAlpha,
colorFilter: ColorFilter? = null
)
Image(
painter = painterResource(id = R.drawable.android_developers),
contentDescription = "android_developers",
alignment = Alignment.Center,
contentScale = ContentScale.Crop,
alpha = 0.5f,
colorFilter = ColorFilter.colorMatrix(ColorMatrix()),
modifier = Modifier.fillMaxWidth()
)
顯示結果
範例程式:
Image(
painter = rememberAsyncImagePainter(model = "https://example.com/image.jpg"),
contentDescription = null,
)
顯示結果
preview又沒有顯示,模擬器和手機才有顯示下載的圖片
https://www.jetpackcompose.net/image-in-jetpack-compose
https://coil-kt.github.io/coil/compose/