Image.RotateFlip(RotateFlipType) 方法

定义

旋转、翻转或者同时旋转和翻转 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 成员,指定要应用于该图像的旋转和翻转的类型。

示例

下面的代码示例演示如何对 ImageRotateFlipType 枚举调用 RotateFlip 方法。

此示例旨在与包含 PictureBox 命名 PictureBox1 和名为 的按钮 Button1的 Windows 窗体一起使用。 将代码粘贴到窗体中,从窗体的构造函数调用InitializeBitmap,并与按钮的事件Click相关联Button1_Click。 确保位图的文件路径在系统上有效。

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 顺时针旋转图像。

如果要在图像旋转后在图像上绘图,应始终从图像中检索新的图形对象,否则可能会出现异常。

适用于