Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void RotateImage2(Bitmap bitmap, Double angle)
- {
- angle = angle % 360;
- if (angle > 180)
- angle -= 360;
- double originX = pictureBox1.Image.Width / 2;
- double originY = pictureBox1.Image.Height / 2;
- 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));
- double newx, newy;
- int x, y;
- for (x = 0; x < bitm.Width; x++)
- {
- for (y = 0; y < bitm.Height; y++)
- {
- newx = (x - originX) * Math.Cos(angle) - (y - originY) * Math.Sin(angle) + originX;
- newy = (x - originY) * Math.Sin(angle) + (y - originY) * Math.Cos(angle) + originY;
- newImg.SetPixel((int)newx, (int)newy, bitm.GetPixel(x, y));
- }
- }
- bitm = newImg;
- pictureBox1.Image = new Bitmap(bitm);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement