Does anyone know of a good way (example) of taking...
# compose
a
Does anyone know of a good way (example) of taking a landscape image and rotating it to fit the screen in portrait mode. I am trying to use the .rotate modifier but I've noticed that it messes with the images size for some reason
z
Can you elaborate on how it messes with the size?
a
Hi Zach, I am trying to render

thisâ–¾

image as you can see this is more of landscape image which if I render it like it is will leader to a smaller image on screen. So I want to rotate the image and then show it in a landscape view, that fills the entire screen. I am using the test code in the snippet. When I use the code as is I see the result in #1. this result is expected since I am cropping a landscape image in a mostly potrait fashion and I expected this to be the outcome. We are good till here. Next I add a
.rotate(90f)
modifier after the
.clip
modifier to the image and I get #2 as the result. If you see the outcome you'll see that the image is for some odd reason is clipped on both top and bottom ends. It's centered in the middle. To me it seems like if we can think of the image being a container and the pixels. The container stayed the same as #1 but the pixels were rotated internally so it's still the same portrait image but rotated which kinda leads to it being cut off. I am not sure if I am doing something wrong but I would love hear if you have thoughts.
First one the #1 and second is #2 and the last one is what I am hoping to achieve
The follow change yields this so, I was kinda right the pixels have shifted but the image container remains the same 🤔
Copy code
BoxWithConstraints(Modifier.background(Color.Blue)) {
    Image(
        painter = remotePainter,
        modifier = Modifier
            .width(maxWidth)
            .height(maxHeight)
            .padding(10.dp)
            .clip(MaterialTheme.shapes.medium)
            .background(Color.Green)
            .rotate(90f),
        contentDescription = "contentDescription",
        contentScale = ContentScale.Crop
    )
}
Changing the
contentScale = ContentScale.Fit
yields the following result, which leads me to believe that
ContentScale.Crop
doesn't work properly because I would assume that crop would just scale the this particular image till, it fills the container