Rotate a BitmapImage

≡放荡痞女 提交于 2019-12-19 10:02:06

问题


I want to rotate a bitmap image I wrote some code and it work

TransformedBitmap TempImage = new TransformedBitmap();

TempImage.BeginInit();
TempImage.Source = MyImageSource; // MyImageSource of type BitmapImage

RotateTransform transform = new RotateTransform(90);
TempImage.Transform = transform;
TempImage.EndInit();

image1.Source = TempImage;

but I want that MyImageSource get this modification, because like that if I click again in the button nothing happen and this normal it get the first form of my image, and also I want it to take this form because I have to save it after modification.

why I have to do this:

I have some tiff image to read some of them can be not in the right form I want to add flip 90° the user click on it until the image return to the right form and when he click on flip the image will be saved(replaced) on disk in the actual form chosen by user


回答1:


How about this?

var transformBitmap = (TransformedBitmap)image1.Source;
RotateTransform rotateTransform = (RotateTransform)(transformBitmap.Transform);
rotateTransform.Angle += 90;
image1.Source = transformBitmap.Clone();



回答2:


How about this:

BitmapImage image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad;
image.UriSource = new Uri(ImagePath);

// here
image.Rotation = Rotation.Rotate270; // or 90, 0, 180

image.EndInit();


来源:https://stackoverflow.com/questions/7309086/rotate-a-bitmapimage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!