在Winform中怎么实现图片的旋转,比如说实现仪表盘功能,看代码吧,看太不懂的欢迎问
1 float cnt = -60; //旋转的角度 2 3 //Timer定时器 4 private void timer1_Tick(object sender, EventArgs e) 5 { 6 timer1.Enabled = false; 7 Image img = Image.FromFile(@"F:\Hanzhaoxun\公司软件备份\其他\仪表盘\指针.png"); //图片路径 8 cnt += 4; 9 if (cnt >= 25) 10 { 11 cnt = -60; 12 } 13 this.pictureBox1.Image = RotateImage(img, cnt); 14 label1.Text = cnt.ToString(); 15 timer1.Enabled = true; 16 } 17 18 //实现图片旋转的方法 19 public static Image RotateImage(Image img, float a) 20 { 21 Bitmap b = new Bitmap(img.Width, img.Height); 22 Graphics g = Graphics.FromImage(b); 23 g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2); 24 g.RotateTransform(a); 25 g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2); 26 g.InterpolationMode = InterpolationMode.HighQualityBicubic; 27 g.DrawImage(img, new Point(0, 0)); 28 g.Dispose(); 29 return b; 30 }