pooja
pooja

Reputation: 95

How to rotate an image by 90 degrees on every button click in Xamarin forms application?

I am using the Plugin. Media to pick a photo from my gallery. I would like to provide the users an option to rotate the image when they click on it.

When I use the rotate property, I am able to rotate the image once. But, I would like to rotate it by 90 degrees every time the user clicks on a button.

if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await  DisplayAlert("Photos Not Supported", "Permission not granted 
                                    to photos", "OK");
                    return;
                }
                var file =   Plugin.Media.CrossMedia.Current.PickPhotoAsync(new 
                                  Plugin.Media.Abstractions.PickMediaOptions
                {
                    PhotoSize = Plugin.Media.Abstractions.PhotoSize.Small
                });
                if (file == null)
                    return;
                imageProfile.Source = ImageSource.FromStream(() =>
                {
                    var stream = file.Result.GetStream();
                    file.Result.Dispose();
                    return stream;
                });

public void rotateButton_Clicked(object sender, Event args e) {

           imageProfile.RotateX(90);
           // This event allows me to rotate the image only once.
}

Upvotes: 1

Views: 2784

Answers (1)

Jason
Jason

Reputation: 89102

int angle = 0;

public void rotateButton_Clicked(object sender, Event args e) {

    angle += 90;
    imageProfile.RotateX(angle);
}

Upvotes: 3

Related Questions