Export (0) Print
Expand All

Image.RotateFlip Method

This method rotates, flips, or rotates and flips the Image.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

public void RotateFlip (
	RotateFlipType rotateFlipType
)
public void RotateFlip (
	RotateFlipType rotateFlipType
)
public function RotateFlip (
	rotateFlipType : RotateFlipType
)
Not applicable.

Parameters

rotateFlipType

A RotateFlipType member that specifies the type of rotation and flip to apply to the image.

If you wish to draw on an image once it has been rotated, you should always retrieve a new graphics object from the image, otherwise an exception could occur.

The following code example demonstrates how to set the RotateFlip property of an Image and the RotateFlipType enumeration.

This example is designed to be used with a Windows Form that contains a PictureBox named PictureBox1 and a button named Button1. Paste the code into a form, call InitializeBitmap from the form's constructor, and associate Button1_Click with the button's Click event. Ensure the file path to the bitmap is valid on your system.

Bitmap bitmap1;

private void InitializeBitmap()
{
    try
    {
        bitmap1 = (Bitmap)Bitmap.FromFile(@"C:\Documents and Settings\" + 
            @"All Users\Documents\My Music\music.bmp");
        PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
        PictureBox1.Image = bitmap1;
    }
    catch(System.IO.FileNotFoundException)
    {
        MessageBox.Show("There was an error." + 
            "Check the path to the bitmap.");
    }


}

private void Button1_Click(System.Object sender, System.EventArgs e)
{

    if (bitmap1 != null)
    {
        bitmap1.RotateFlip(RotateFlipType.Rotate180FlipY);
        PictureBox1.Image = bitmap1;
    }

}

private Bitmap bitmap1;

private void InitializeBitmap()
{
    try {
        bitmap1 = ((Bitmap)(Bitmap.FromFile(("C:\\Documents and Settings\\"
            + "All Users\\Documents\\My Music\\music.bmp"))));
        pictureBox1.set_SizeMode(PictureBoxSizeMode.AutoSize);
        pictureBox1.set_Image(bitmap1);
    }
    catch (System.IO.FileNotFoundException exp) {
        MessageBox.Show(("There was an error." 
            + "Check the path to the bitmap."));
    }
} //InitializeBitmap

private void button1_Click(Object sender, System.EventArgs e)
{
    if (bitmap1 != null) {
        bitmap1.RotateFlip(RotateFlipType.Rotate180FlipY);
        pictureBox1.set_Image(bitmap1);
    }
} //button1_Click

Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft