Image.RotateFlip(RotateFlipType) Metodo

Definizione

Ruota, capovolge o ruota e capovolge l'oggetto 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)

Parametri

rotateFlipType
RotateFlipType

Membro RotateFlipType che specifica il tipo di rotazione e capovolgimento da applicare all'immagine.

Esempio

Nell'esempio di codice seguente viene illustrato come chiamare il RotateFlip metodo su un Image oggetto e l'enumerazione RotateFlipType .

Questo esempio è progettato per essere usato con un form Windows contenente un PictureBox denominato PictureBox1 e un pulsante denominato Button1. Incollare il codice in una maschera, chiamare InitializeBitmap dal costruttore del modulo e associarlo Button1_Click all'evento del Click pulsante. Verificare che il percorso del file della bitmap sia valido nel sistema.

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

Commenti

Il RotateFlip metodo ruota l'immagine in senso orario.

Se vuoi disegnare su un'immagine una volta ruotata, dovresti sempre recuperare un nuovo oggetto grafico dall'immagine, altrimenti potrebbe verificarsi un'eccezione.

Si applica a