Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How do I rotate an image but have it remain within its container?

$
0
0

My previous post somehow got deleted/locked so I am reposting it...?

I am trying to rotate an image but have it remain within the container, to solve it, i tried scaling the image based upon its width and height. Problem I'be been getting is that that when I rotate the image in a jpeg viewer so that width becomes height and height becomes width, and then try to scale the image after rotation, the image.width and image.height doesnt get updated even though the image on-screen in the application looks like it has been rotated.

Previous person said its because the bitmap didnt get updated. Is there a way to get the actual width/height of the image that is being displayed instead of the bitmap width/height?

        private void ScaleImage(Image image)
        {
            double x = image.Width;
            double y = image.Height;
            if (image.Height> image.Width)
            {
                x = image.Height;
                y = image.Width;
            }
            if (image_rotation / 90 % 2 != 0)
            {
                image.Scale = y/x;
            }
            else
            {
                image.Scale = 1;
            }
        }
        private void W2RLeft_Clicked(object sender, EventArgs e)
        {
            image_rotation -= 90;
            ScaleImage(w2Image);
            w2Image.RotateTo(image_rotation, 100);
        }

        private void W2RRight_Clicked(object sender, EventArgs e)
        {
            image_rotation += 90;
            ScaleImage(w2Image);
            w2Image.RotateTo(image_rotation, 100);
        }

How would I solve this issue, or.. is there a better way of solving it? thanks


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>