public static Bitmap RotateImage(Image image, float angle)
{
if (image == null)
throw new ArgumentNullException("image");
float dx = image.Width / 2.0f;
float dy = image.Height / 2.0f;
Bitmap rotatedBmp = new Bitmap(image.Width, image.Height);
rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
Graphics g = Graphics.FromImage(rotatedBmp);
g.TranslateTransform(dx, dy);
g.RotateTransform(angle);
g.TranslateTransform(-dx, -dy);
g.DrawImage(image, new PointF(0, 0));
return rotatedBmp;
}
void tm_Elapsed(object sender, EventArgs e)
{
if (isStart)
{
angle += 5;
if (angle >= 359) angle = 0;
RotateImage(pic1, Properties.Resources._1, angle);
}
}
private void RotateImage(PictureBox pb, Image img, float angle)
{
if (img == null || pb.Image == null)
return;
Image oldImage = pb.Image;
pb.Image = Utilities.RotateImage(img, angle);
if (oldImage != null)
{
oldImage.Dispose();
}
}