如何在Xamarin表单应用程序中单击按钮时将图像旋转90度?

问题描述 投票:1回答:1

我正在使用插件。媒体从我的画廊中挑选照片。我想为用户提供一个单击图像时旋转图像的选项。

当我使用rotate属性时,我可以旋转图像一次。但是,我希望每次用户单击按钮时将其旋转90度。

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.
}
xamarin xamarin.forms xamarin.android xamarin.ios
1个回答
3
投票
int angle = 0;

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

    angle += 90;
    imageProfile.RotateX(angle);
}
© www.soinside.com 2019 - 2024. All rights reserved.