Mayur Ghatkar

Mayur Ghatkar

  • NA
  • 113
  • 8.1k

About Rotation image in any Angle

Jun 28 2017 7:16 AM
Hello,
 
I am dealing with images in my project. I am giving some angle and my Image should rotate in that angle. But It only rotate in multiples of 90 as I am using TransformedBitmap.
 
So please help me for rotating image in any angle and after rotation new image will be saved.
 
thanks in advanced. 
 
Source code is:-
 
Image image = new Image();
BitmapImage bitmapImage = new BitmapImage();
bitmapImage.BeginInit();
bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
bitmapImage.UriSource = new Uri(_DataSource.BackgroundImageFullPath);
bitmapImage.EndInit();
image.Source = bitmapImage;
BitmapSource img = (BitmapSource)(image.Source);
//rotate tif and save
CachedBitmap cache = new CachedBitmap(img, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
TransformedBitmap tb = new TransformedBitmap(cache, new RotateTransform(imgAngle));
TiffBitmapEncoder encoder = new TiffBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(tb));
using (FileStream file = File.OpenWrite(_DataSource.BackgroundImageFullPath))
{
encoder.Save(file);
}
 

Answers (4)