1

trying to rotate a bitmapImage 90 degrees but have been unable so far.

this: http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapimage.rotation(v=vs.110).aspx#feedback

doesn't actually work. TransformedBitmap type does not exist and and BitmapImage has no .beginInit() and .EndInit() methods

I already have added

using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;

have MS forgot to update their documentation, am I doing something wrong or is this actually not meant for Windows 8?

http://msdn.microsoft.com/en-us/library/windows/apps/windows.graphics.imaging.bitmaptransform.aspx I also found this but were unable to find an example of using it.

Krekkon
  • 1,349
  • 14
  • 35
Essah
  • 899
  • 2
  • 8
  • 20

3 Answers3

1

The TransformedBitmap type does exist. But you have to add a reference to you project to PresentationCore.dll

Then follow this example: http://msdn.microsoft.com/en-us/library/aa970271(v=vs.110).aspx

(Stolen from the link)

BitmapImage myBitmapImage = new BitmapImage();

myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg");

myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();

TransformedBitmap myRotatedBitmapSource = new TransformedBitmap();

myRotatedBitmapSource.BeginInit();

myRotatedBitmapSource.Source = myBitmapImage;

myRotatedBitmapSource.Transform = new RotateTransform(90);
myRotatedBitmapSource.EndInit()
ohlmar
  • 958
  • 8
  • 17
  • did this, and also referenced WindowsBase as required. beginInit and endInit are still not being found and furthermore after changing to x86 architecture as required by the added references I now get cannot find type System.ComponentModel.TypeConverter in module System.dll which seems to be related to the fact that it does not exist for store apps as described here (next comment) – Essah Feb 18 '14 at 09:51
  • http://stackoverflow.com/questions/10509955/windows-metro-style-app-occur-error-with-google-data-api-library – Essah Feb 18 '14 at 09:51
  • That is wierd. I tried it and it worked just fine. Only needed these usings `using System.Windows.Media; using System.Windows.Media.Imaging;` – ohlmar Feb 18 '14 at 10:00
  • I am not. But if my answers didnt help im afraid I cant help you anymore :( – ohlmar Feb 18 '14 at 10:10
0

Maybe this can help in your situation:

Code-Behind:

var image = new Image
                    { 
                        Height = 50,
                        Width = 50,
                        RenderTransform = new RotateTransform() 
                        { 
                        Angle = 90, 
                        CenterX = 25, //The prop name maybe mistyped 
                        CenterY =25 //The prop name maybe mistyped 
                        },
                        Source = new BitmapImage(new Uri("MyImageSoruce"))
                    };

MainGrid.Children.Add(image);
Krekkon
  • 1,349
  • 14
  • 35
  • that would probably solve the issue of rotating the image for displaying but since I need to save the rotated BitmapImage (that is the C# type) after being rotated it's not a solution :( – Essah Feb 19 '14 at 09:47
  • I Got it, i know its hack, but what if you rotate the image and save it into a file with cropping? :D – Krekkon Feb 19 '14 at 13:38
0

http://msdn.microsoft.com/en-us/library/windows/apps/jj709937.aspx

this as suggested by Mihai Hantea ended up doing the trick. Turns out I was missing an Await command on a .FlushAsync(). After addding the await it suddenly came together and worked brilliantly.

Essah
  • 899
  • 2
  • 8
  • 20