c# image rotations
<p>I need some help with an issue that is truly giving me a headache. It's an application that allows the user to load an image file and then rotate the image clockwise or counterclockwise 90 degrees. The code works fine, however if the user rotates the image clockwise and then decides to rotate it back to the initial position via counterclockwise the image is not where it should be. I'm not sure what I am missing as I am very new to c#. Below is the code I am using for the clockwise rotation.</p>

<pre><code> private int cW = 0;


    private void button6_Click(object sender, RoutedEventArgs e)
    {
        RotateTransform rotateTransform = new RotateTransform();
        rotateTransform.CenterX = image1.ActualWidth / 2.0;
        rotateTransform.CenterY = image1.ActualHeight / 2.0;
        cW += 90;

        rotateTransform.Angle = cW;

        TransformGroup transformGroup = new TransformGroup();
        transformGroup.Children.Add(rotateTransform);

        image1.RenderTransform = transformGroup; 
    }
</code></pre>

<p>I have completely changed the code using if/else statements. The following gives me the result I was looking for.</p>

<pre><code>    RotateTransform cwRotateTransform;
    private void button6_Click(object sender, RoutedEventArgs e)
    {

        if (cwRotateTransform == null)
        {

            cwRotateTransform = new RotateTransform();

        }

        image1.LayoutTransform = cwRotateTransform;

        if (cwRotateTransform.Angle == 360)

            cwRotateTransform.Angle = 0;

        else cwRotateTransform.Angle += 90;


    }
</code></pre>

<p>For counter-clockwise simply change "90" to "-90" for else cwRotateTransform.Angle</p>
