Advertisement
waydub12

Rotation C#

Apr 11th, 2022
1,133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1.         private static Bitmap RotateImage(Image image, PointF offset, float angle)
  2.         {
  3.             var rotatedBmp = new Bitmap(image.Width, image.Height);
  4.             rotatedBmp.SetResolution(image.HorizontalResolution, image.VerticalResolution);
  5.             var g = Graphics.FromImage(rotatedBmp);
  6.             g.TranslateTransform(offset.X, offset.Y);
  7.             g.RotateTransform(angle);
  8.             g.TranslateTransform(-offset.X, -offset.Y);
  9.             g.DrawImage(image, new PointF(0, 0));
  10.             return rotatedBmp;
  11.         }
  12.  
  13.         private void buttonRotate_Click(object sender, EventArgs e)
  14.         {
  15.             Cursor = Cursors.WaitCursor;
  16.  
  17.             float angle = (float) Convert.ToDouble(textBoxAngleRotate.Text);
  18.             PointF offset = new PointF((float) Convert.ToSingle(
  19.                 textBoxOffsetRotateX.Text) , (float) Convert.ToSingle(textBoxOffsetRotateY.
  20.                 Text));
  21.             bmpAsli = (Bitmap)pictureBoxInput.Image;
  22.             bmpHasil = new Bitmap(bmpAsli.Width, bmpAsli.Height);
  23.             bmpHasil = RotateImage(bmpAsli, offset, angle);
  24.             pictureBoxOutput.Image = bmpHasil;
  25.  
  26.             Cursor = Cursors.Default;
  27.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement