Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. public void RotateImage2(Bitmap bitmap, Double angle)
  2.         {
  3.             angle = angle % 360;
  4.             if (angle > 180)
  5.                 angle -= 360;
  6.  
  7.             double originX = pictureBox1.Image.Width / 2;
  8.             double originY = pictureBox1.Image.Height / 2;
  9.  
  10.             Bitmap newImg = new Bitmap((int)Math.Sqrt(bitm.Height * bitm.Height + bitm.Width * bitm.Width), (int)Math.Sqrt(bitm.Height * bitm.Height + bitm.Width * bitm.Width));
  11.             double newx, newy;
  12.             int x, y;
  13.             for (x = 0; x < bitm.Width; x++)
  14.             {
  15.                 for (y = 0; y < bitm.Height; y++)
  16.                 {
  17.                     newx = (x - originX) * Math.Cos(angle) - (y - originY) * Math.Sin(angle) + originX;
  18.                     newy = (x - originY) * Math.Sin(angle) + (y - originY) * Math.Cos(angle) + originY;
  19.                     newImg.SetPixel((int)newx, (int)newy, bitm.GetPixel(x, y));
  20.                 }
  21.             }
  22.             bitm = newImg;
  23.             pictureBox1.Image = new Bitmap(bitm);
  24.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement