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);

 

posted @ 2020-05-27 16:09  小大大小  阅读(1451)  评论(0编辑  收藏  举报