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;
}
}
'# 4) .Net ( Vs 2010 ) > C#' 카테고리의 다른 글
WINFORM] 컨트롤 동적 사이즈 조절... (0) | 2013.03.26 |
---|---|
WinForm] 단축키 (0) | 2012.10.11 |
2010 WinForm ] 컨트롤 리사이징 예제... (0) | 2012.07.20 |
.Net] 버튼 Pressed Event!! (0) | 2012.05.09 |
.NET ] 멀티 랭귀지 지원 ... (0) | 2012.03.06 |