Akrem
Akrem

Reputation: 4652

Rotate a BitmapImage

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

Upvotes: 3

Views: 11645

Answers (2)

Khalil Khalaf
Khalil Khalaf

Reputation: 9397

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();

Upvotes: 3

Howard
Howard

Reputation: 3848

How about this?

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

Upvotes: 2

Related Questions