问题
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