Image.RotateFlip(RotateFlipType) 方法

定义

旋转、翻转或者同时旋转和翻转 ImageRotates, flips, or rotates and flips the Image.

public:
 void RotateFlip(System::Drawing::RotateFlipType rotateFlipType);
public void RotateFlip (System.Drawing.RotateFlipType rotateFlipType);
member this.RotateFlip : System.Drawing.RotateFlipType -> unit
Public Sub RotateFlip (rotateFlipType As RotateFlipType)

参数

rotateFlipType
RotateFlipType

RotateFlipType 成员,指定要应用于该图像的旋转和翻转的类型。A RotateFlipType member that specifies the type of rotation and flip to apply to the image.

示例

下面的代码示例演示如何对 RotateFlip Image 和枚举调用方法 RotateFlipTypeThe following code example demonstrates how to call the RotateFlip method on an Image and the RotateFlipType enumeration.

此示例旨在与包含名为的和名为的按钮的 Windows 窗体一起使用 PictureBox PictureBox1 Button1This example is designed to be used with a Windows Form that contains a PictureBox named PictureBox1 and a button named Button1. 将代码粘贴到窗体中, InitializeBitmap 从窗体的构造函数调用,并 Button1_Click 与按钮的 Click 事件关联。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;
void InitializeBitmap()
{
   try
   {
      bitmap1 = dynamic_cast<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." );
   }

}

void Button1_Click( System::Object^ /*sender*/, System::EventArgs^ /*e*/ )
{
   if ( bitmap1 != nullptr )
   {
      bitmap1->RotateFlip( RotateFlipType::Rotate180FlipY );
      PictureBox1->Image = bitmap1;
   }
}
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;
    }
}
Dim bitmap1 As Bitmap

Private Sub InitializeBitmap()
    Try
        bitmap1 = CType(Bitmap.FromFile("C:\Documents and Settings\All Users\" _
            & "Documents\My Music\music.bmp"), Bitmap)
        PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize
        PictureBox1.Image = bitmap1
    Catch ex As System.IO.FileNotFoundException
        MessageBox.Show("There was an error. Check the path to the bitmap.")
    End Try


End Sub

Private Sub Button1_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles Button1.Click

    If bitmap1 IsNot Nothing Then
        bitmap1.RotateFlip(RotateFlipType.Rotate180FlipY)
        PictureBox1.Image = bitmap1
    End If

End Sub

注解

RotateFlip方法顺时针旋转图像。The RotateFlip method rotates the image clockwise.

如果希望在图像旋转后绘制图像,应始终从图像中检索新的图形对象,否则可能会出现异常。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.

适用于