How to: Rotate an Image
This example shows how to rotate an image 90 degrees by using a Rotation property of a BitmapImage.
Example
<Image Width="150" Margin="5" Grid.Column="0" Grid.Row="1">
<Image.Source>
<BitmapImage UriSource="/sampleImages/watermelon.jpg" Rotation="Rotate90" />
</Image.Source>
</Image>
//Create Image element
Image rotated270 = new Image();
rotated270.Width = 150;
//Create source
BitmapImage bi = new BitmapImage();
//BitmapImage properties must be in a BeginInit/EndInit block
bi.BeginInit();
bi.UriSource = new Uri(@"pack://application:,,/sampleImages/watermelon.jpg");
//Set image rotation
bi.Rotation = Rotation.Rotate270;
bi.EndInit();
//set image source
rotated270.Source = bi;
'Create Image element
Dim rotated270 As New Image()
rotated270.Width = 150
'Create source
Dim bi As New BitmapImage()
'BitmapImage properties must be in a BeginInit/EndInit block
bi.BeginInit()
bi.UriSource = New Uri("pack://application:,,/sampleImages/watermelon.jpg")
'Set image rotation
bi.Rotation = Rotation.Rotate270
bi.EndInit()
'set image source
rotated270.Source = bi
Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, see our contributor guide.
.NET Desktop feedback
Feedback
https://aka.ms/ContentUserFeedback.
Coming soon: Throughout 2024 we will be phasing out GitHub Issues as the feedback mechanism for content and replacing it with a new feedback system. For more information see:Submit and view feedback for