I am using clip to trim an Image using Compose, to show only the left edge part of the image. But it maintains the width with blank space. How can I crop the right part(marked in red)?
I tried setting a custom width for Image but its not working as expected.
Here is the code I am using,
object CropShape : Shape {
override fun createOutline(
size: androidx.compose.ui.geometry.Size,
layoutDirection: LayoutDirection,
density: Density
): Outline = Outline.Rectangle(
Rect(Offset.Zero, androidx.compose.ui.geometry.Size((58 * density.density), size.height))
)
}
@Composable
private fun test(){
Image(
modifier = Modifier
.height(142.dp)
.clip(CropShape)
.padding(start = 20.dp, bottom = 20.dp)
.rotate(TiltedImageRotation)
painter = resourcePainter(R.drawable.image),
contentScale = ContentScale.FillHeight,
contentDescription = null,
)
}
Setting the width is the right approach, you just need proper
alignment
I think - usealignment = Alignment.CenterStart
to see the start of your image and not the center like on your second picture:If you want to align with some offset, as suggested in the other answer, that can be done with
Alignment
too, and more easily: