Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void rotate(int angle)
- {
- int newSize = (int)Math.Sqrt(bm.Width * bm.Width + bm.Height * bm.Height);
- rotatedBm = new Bitmap(newSize, newSize);
- int x0 = bm.Width / 2;
- int y0 = bm.Height / 2;
- int difX = (int)(newSize / 2) - x0;
- int difY = (int)(newSize / 2) - y0;
- int newX, newY;
- double angleInRadian = (angle * Math.PI / 180);
- for (int x = 0; x < bm.Width; x++)
- for (int y = 0; y < bm.Height; y++)
- {
- Color c = bm.GetPixel(x, y);
- newX = (int) ((x-x0)*Math.Cos(angleInRadian) - (y - y0) *Math.Sin(angleInRadian) + x0) + difX;
- newY = (int)((x-x0) * Math.Sin(angleInRadian) + (y - y0) *Math.Cos(angleInRadian) + y0) + difY;
- rotatedBm.SetPixel(newX, newY, c);
- }
- pictureBox1.Image = rotatedBm;
- pictureBox1.Refresh();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement