Robert92
Robert92

Reputation: 11

C# WPF - Rotation of Image

I'm just trying to get the rotation value of an image within a Canvas. Unlike the X- and Y-Values (Canvas.GetLeft etc.) I do not know hot to get the rotation value. The only possible way I've found was RotateTransform, but I always get a NullReferenceException despite the fact that I can get all attributes from img (see code).

foreach (var child in cv_Layout.Children) {
   if (child.GetType() == typeof(Image)){
       Image img = (Image)child;
       RotateTransform rotation = img.RenderTransform as RotateTransform;
       lbl_Test.Content = rotation.Angle;
   }
}

Is there something I'm missing?

Thank you very much! Greetings!

Upvotes: 0

Views: 111

Answers (1)

Robert92
Robert92

Reputation: 11

today I've solved it. Before you can get the possibility to access the RotateTransform-Angle, a RenderTransform initialization at img-level has to be done.

...
rotation = new RotateTransform(0);
img.RenderTransform = rotation;
...

Afterwards it is possible to get Angle, CenterPoint or whatever.

...
double Rot_Z = img.RenderTransform as RotateTransform).Angle;
...

Maybe it's helpful for somebody :)

Greetings!

Upvotes: 1

Related Questions