C# 用代码C-UWP旋转位图

C# 用代码C-UWP旋转位图,c#,bitmap,rotation,windows-10,uwp,C#,Bitmap,Rotation,Windows 10,Uwp,如何将位图顺时针旋转90度?我正在使用下一个代码从存储器中读取图像: public async void GetImage() { string filename = code + ".jpg"; Windows.Storage.StorageFile sampleFile = await Windows.Storage.KnownFolders.CameraRoll.GetFileAsync(filename);

如何将位图顺时针旋转90度?我正在使用下一个代码从存储器中读取图像:

public async void GetImage()
    {
        string filename = code + ".jpg";

        Windows.Storage.StorageFile sampleFile = 
            await Windows.Storage.KnownFolders.CameraRoll.GetFileAsync(filename);


        BitmapImage img = new BitmapImage();

        img = await LoadImage(sampleFile);

        imageMain.Source = img;

    }

        private static async Task<BitmapImage> LoadImage(StorageFile file)
    {
        BitmapImage bitmapImage = new BitmapImage();
        FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);

        bitmapImage.SetSource(stream);

        return bitmapImage;
    }

我想让图像旋转。bitmapImage.Rotate在UWP上不工作。什么是解决方案?

这可以通过上课来实现

暗藏

在XAML中

**如果您注意到,您可以看到CenterX和CenterY是实际图像大小的一半

祝你好运。

RotateTransform _rotateTransform = new RotateTransform()
{
    CenterX = imageMain.ActualWidth/2,
    CenterY = imageMain.ActualHeight/2,
    Angle = 90
};
imageMain.RenderTransform = _rotateTransform;
<Image Stretch="Fill" Source="Assets/Windows.jpg" x:Name="imageMain" Width="500" Height="500">
    <Image.RenderTransform>
        <RotateTransform CenterX="250" CenterY="250" Angle="90"/>
    </Image.RenderTransform>
</Image>