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 成員,指定要套用至影像的旋轉和翻轉類型。

範例

下列程式代碼範例示範如何在 和 RotateFlipType 列舉上Image呼叫 RotateFlip 方法。

此範例的設計目的是要與 Windows Form 搭配使用,其中包含 PictureBox 具名 PictureBox1 的 和名為的 Button1按鈕。 將程式代碼貼到表單中、從表單的建構函式呼叫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 會順時針旋轉影像。

如果您想要在影像旋轉後繪製影像,您應該一律從影像擷取新的圖形對象,否則可能會發生例外狀況。

適用於