GDI+] 이미지 회전!
회전!! 뱅글 뱅글..
Resource.R 은 회전 될 이미지
public partial class Form1 : Form
{
float angle = 0f;
Timer tm = new Timer();
public Form1()
{
InitializeComponent();
tm.Interval = 500;
tm.Tick += new EventHandler(tm_Tick);
tm.Start();
}
void tm_Tick(object sender, EventArgs e)
{
angle += 10;
Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
e.Graphics.DrawImage( rotateImage( Resources.r , angle ), 100f, 100f);
}
/// <summary>
/// 튜토리얼 : http://www.switchonthecode.com/tutorials/csharp-tutorial-image-editing-rotate
/// </summary>
/// <param name="b"></param>
/// <param name="angle"></param>
/// <returns></returns>
private Bitmap rotateImage(Bitmap b, float angle)
{
//create a new empty bitmap to hold rotated image
Bitmap returnBitmap = new Bitmap(b.Width, b.Height);
//make a graphics object from the empty bitmap
Graphics g = Graphics.FromImage(returnBitmap);
//move rotation point to center of image
g.TranslateTransform((float)b.Width / 2, (float)b.Height / 2);
//rotate
g.RotateTransform(angle);
//move image back
g.TranslateTransform(-(float)b.Width / 2, -(float)b.Height / 2);
//draw passed in image onto graphics object
g.DrawImage(b, new Point(0, 0));
return returnBitmap;
}
}