Image.RotateFlip(RotateFlipType) Methode

Definition

Dreht, kippt oder dreht und kippt die 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)

Parameter

rotateFlipType
RotateFlipType

Ein RotateFlipType Element, das den Typ der Drehung angibt und kippt, die auf das Bild angewendet werden soll.

Beispiele

Im folgenden Codebeispiel wird veranschaulicht, wie die RotateFlip Methode für eine Image und die RotateFlipType Enumeration aufgerufen wird.

Dieses Beispiel wurde für die Verwendung mit einem Windows Formular entwickelt, das ein PictureBox namens PictureBox1 und eine Schaltfläche mit dem Namen Button1 enthält. Fügen Sie den Code in ein Formular ein, rufen Sie InitializeBitmap den Konstruktor des Formulars auf, und ordnen Sie Button1_Click es dem Ereignis der Schaltfläche Click zu. Stellen Sie sicher, dass der Dateipfad zur Bitmap auf Ihrem System gültig ist.

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

Hinweise

Die RotateFlip Methode dreht das Bild im Uhrzeigersinn.

Wenn Sie auf ein Bild zeichnen möchten, nachdem es gedreht wurde, sollten Sie immer ein neues Grafikobjekt aus dem Bild abrufen, andernfalls kann eine Ausnahme auftreten.

Gilt für: