C#实现图片绕中心旋转
添加旋转函数:
public static Bitmap picRotate(Bitmap bmp,int angle) { Bitmap reBmp = new Bitmap(bmp.Width,bmp.Height); Graphics g = Graphics.FromImage(reBmp); g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High; g.TranslateTransform((float)bmp.Width/2,(float)bmp.Height/2); g.RotateTransform(angle); g.TranslateTransform(-(float)bmp.Width/2,-(float)bmp.Height/2); g.DrawImage(bmp,new Point(0,0)); return reBmp; }
使用实例:
Image image = Image.FromFile("car.png");
Bitmap bmp = new Bitmap(image); pictureBox1.BackgroundImage = picRotate(bmp,30);