Image.RotateFlip(RotateFlipType) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
旋轉、翻轉,或旋轉並翻轉 。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 成員指定要應用在影像上的旋轉與翻轉類型。
範例
以下程式碼範例示範如何在 和 RotateFlipImage 枚舉上呼叫RotateFlipType該方法。
此範例設計用於包含一個名為 PictureBoxPictureBox1 的 Windows 表單,以及一個名為 Button1 的按鈕。 將程式碼貼到表單中,從表單的建構子呼叫InitializeBitmap,並與按鈕事件Button1_Click關聯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 方法將影像順時針旋轉。
如果你想在旋轉過的影像上繪圖,應該總是從影像中取得新的圖形物件,否則可能會發生例外。