Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. private void rotate(int angle)
  2. {
  3. int newSize = (int)Math.Sqrt(bm.Width * bm.Width + bm.Height * bm.Height);
  4. rotatedBm = new Bitmap(newSize, newSize);
  5. int x0 = bm.Width / 2;
  6. int y0 = bm.Height / 2;
  7. int difX = (int)(newSize / 2) - x0;
  8. int difY = (int)(newSize / 2) - y0;
  9. int newX, newY;
  10. double angleInRadian = (angle * Math.PI / 180);
  11. for (int x = 0; x < bm.Width; x++)
  12. for (int y = 0; y < bm.Height; y++)
  13. {
  14. Color c = bm.GetPixel(x, y);
  15. newX = (int) ((x-x0)*Math.Cos(angleInRadian) - (y - y0) *Math.Sin(angleInRadian) + x0) + difX;
  16. newY = (int)((x-x0) * Math.Sin(angleInRadian) + (y - y0) *Math.Cos(angleInRadian) + y0) + difY;
  17. rotatedBm.SetPixel(newX, newY, c);
  18. }
  19. pictureBox1.Image = rotatedBm;
  20. pictureBox1.Refresh();
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement