C#实现任意角度旋转图片(方法1)

实现任意角度旋转图像主要使用Graphics类提供的RotateTransform()方法。代码如下:

 1private void button1_Click(objectsender,EventArgse)  
 2    {  
 3      //以任意角度旋转显示图像  
 4      Graphics g=this.panel1.CreateGraphics();  
 5      float MyAngle=0;//旋转的角度  
 6      while(MyAngle<360)  
 7      {  
 8        TextureBrush MyBrush=newTextureBrush(MyBitmap);  
 9        this.panel1.Refresh();  
10        MyBrush.RotateTransform(MyAngle);  
11        g.FillRectangle(MyBrush,0,0,this.ClientRectangle.Width,this.ClientRectangle.Height);  
12        MyAngle+=0.5f;  
13        System.Threading.Thread.Sleep(50);  
14      }  
15    }