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