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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM