以任意角度旋轉圖像示例。
實現任意角度旋轉圖像主要使用Graphics類提供的RotateTransform()方法。代碼如下:
private void button1_Click(object sender, EventArgs e)
{
//以任意角度旋轉顯示圖像
Graphics g = this.panel1.CreateGraphics();
float MyAngle = 0;//旋轉的角度
while (MyAngle < 360)
{
TextureBrush MyBrush = new TextureBrush(MyBitmap);
this.panel1.Refresh();
MyBrush.RotateTransform(MyAngle);
g.FillRectangle(MyBrush, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height);
MyAngle += 0.5f;
System.Threading.Thread.Sleep(50);
}
}