Home

Operations on Bitmaps: Rotating a Picture

     

Introduction

Rotating a picture consists of changing its angular orientation. The Image class supports this operation (with somewhat limited options) through its RotateFlip() method. As mentioned for mirroring and flipping, the value you pass as argument would determine how the operation is carried out.

The members of the RotateFlipType enumeration that are used to rotate a picture are:

  • RotateNoneFlipNone: Nothing would happen
  • Rotate90FlipNone: The picture is rotated at 90� clockwise. As a result, after calling the method with this member, what is on the left of the original picture would be positioned in the top section of the picture. Here is an example:
     
    Original After Calling the Method
    =>
    Notice that, after the method has been called, the person is still holding the remote control with his right hand. Here is an example:
    private void btnRotate_Click(object sender, EventArgs e)
    {
            Bitmap bmpPicture = new Bitmap("person1.gif");
            bmpPicture.RotateFlip(RotateFlipType.Rotate90FlipNone);
            CreateGraphics().DrawImage(bmpPicture, 10, 10);
    }
  • Rotate180FlipNone: The picture is rotated at 90� clockwise twice. This means that the picture is first rotated at 90�, then rotated again at 90�. As a result, after calling the method with this member, what is on the left of the original picture would be positioned in the right section but what is on the top would be positioned to the bottom of the picture. Here is an example:
     
    Original
    After Calling the Method
    Notice that, after the method has been called, the person is still holding the remote control with his right hand. As a result, the remote control is on opposite sites of the pictures, indicating that it is the same hand.
    You can get the same result by calling the method twice with the Rotate90FlipNone member each time:
    private void btnRotate_Click(object sender, EventArgs e)
    {
            Bitmap bmpPicture = new Bitmap("person1.gif");
            bmpPicture.RotateFlip(RotateFlipType.Rotate90FlipNone);
            bmpPicture.RotateFlip(RotateFlipType.Rotate90FlipNone);
            CreateGraphics().DrawImage(bmpPicture, 10, 10);
    }
  • Rotate270FlipNone: The picture is rotated at 90� clockwise three times. This means that the picture is first rotated at 90�, then rotated again at 90�, and then rotated again at 90�. Here is an example:
     
    Original After Calling the Method
    =>
    Notice that, after the method has been called, the person is still holding the remote control with his right hand.
    You can get the same result by calling the method three times with the Rotate90FlipNone member each time:
    private void btnRotate_Click(object sender, EventArgs e)
    {
            Bitmap bmpPicture = new Bitmap("person1.gif");
            bmpPicture.RotateFlip(RotateFlipType.Rotate90FlipNone);
            bmpPicture.RotateFlip(RotateFlipType.Rotate90FlipNone);
            bmpPicture.RotateFlip(RotateFlipType.Rotate90FlipNone);
            CreateGraphics().DrawImage(bmpPicture, 10, 10);
    }
  • Rotate180FlipXY: No real change. Actually, the picture is rotated at 90� four times and then gets back to its original orientation and position:
     
    Original
    After Calling the Method
  • Rotate90FlipX: The picture is mirrored, then rotated at 90� counterclockwise (or rotated at 90� counterclockwise then mirrored):
     
    Original After Calling the Method
    =>
    Notice that, after the method has been called, the person is now holding the remote control with his left hand
  • Rotate180FlipX: The picture is mirrored, then rotated at 180� counterclockwise twice (or rotated at 180� counterclockwise twice then mirrored):
     
    Original
    After Calling the Method
    Notice that, after the method has been called, the person is now holding the remote control with his left hand. As a consequence, the remote control is on the same side of the screen on both pictures (compare with Rotate180FlipNone)
  • Rotate270FlipX: The picture is mirrored, then rotated at 90� counterclockwise three times (or rotated at 90� counterclockwise three times then mirrored):
     
    Original After Calling the Method
    =>
    Notice that, after the method has been called, the person is now holding the remote control with his left hand
  • Rotate90FlipY: Produces the same result as Rotate270FlipX 
  • Rotate270FlipY: Produces the same result as Rotate90FlipX
  • Rotate90FlipXY: Produces the same result as Rotate270FlipNone
  • Rotate270FlipXY: Produces the same result as Rotate90FlipNone
  • RotateNoneFlipXY: Produces the same result as Rotate180FlipNone
 

Home Copyright © 2010-2014, FunctionX