Image.RotateFlip(RotateFlipType) Image.RotateFlip(RotateFlipType) Image.RotateFlip(RotateFlipType) Method

定義

Image の回転、反転、または回転と反転の両方を行います。Rotates, 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

パラメーター

rotateFlipType
RotateFlipType RotateFlipType RotateFlipType

イメージに適用する回転または反転のタイプを指定する RotateFlipType のメンバー。A RotateFlipType member that specifies the type of rotation and flip to apply to the image.

Image RotateFlipRotateFlipType列挙体に対してメソッドを呼び出す方法を次のコード例に示します。The following code example demonstrates how to call the RotateFlip method on an Image and the RotateFlipType enumeration.

この例は、名前PictureBox PictureBox1付きのとという名前Button1のボタンを含む Windows フォームと共に使用するように設計されています。This example is designed to be used with a Windows Form that contains a PictureBox named PictureBox1 and a button named Button1. フォームにコードを貼り付け、フォームInitializeBitmapのコンストラクターからを呼び出して、ボタンButton1_ClickClickイベントに関連付けます。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.

適用対象