Complete the code to display an image from a drawable resource using Image composable.
Image(painter = painterResource(id = [1]), contentDescription = "Sample image")
The painterResource function requires a drawable resource ID to load the image. R.drawable.ic_launcher_foreground is a valid drawable resource.
Complete the code to set the content scale of the Image composable to crop the image.
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "Sample image", contentScale = [1])
ContentScale.Crop scales the image to fill the bounds and crops any overflow, which is useful to fill the space without distortion.
Fix the error in the code by completing the modifier to add padding around the Image composable.
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "Sample image", modifier = Modifier.[1](16.dp))
The padding modifier adds space around the composable. Using padding(16.dp) adds 16 density-independent pixels of space around the image.
Fill both blanks to create an Image composable that fills the max width and has a rounded corner shape.
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = "Sample image", modifier = Modifier.[1]().clip(RoundedCornerShape([2])))
fillMaxWidth() makes the image fill the available width. RoundedCornerShape(16.dp) rounds the corners with a radius of 16 density-independent pixels.
Fill all three blanks to create an Image composable with a content description, a tint color, and a size modifier.
Image(painter = painterResource(id = R.drawable.ic_launcher_foreground), contentDescription = [1], colorFilter = ColorFilter.tint([2]), modifier = Modifier.[3](48.dp))
The contentDescription should be a descriptive string like "App icon" for accessibility. ColorFilter.tint(Color.Red) applies a red tint to the image. Modifier.size(48.dp) sets the image size to 48 density-independent pixels.