如何将位图顺时针旋转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上不起作用。有什么解决办法?
这可以通过RotateTransform类实现
在后面的代码中
RotateTransform _rotateTransform = new RotateTransform()
{
CenterX = imageMain.ActualWidth/2,
CenterY = imageMain.ActualHeight/2,
Angle = 90
};
imageMain.RenderTransform = _rotateTransform;
在XAML中
<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>
**如果您注意到,您可以看到该图像CenterX
,CenterY
它的大小仅为实际图像的一半。
祝你好运。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句