locked
rotation of bitmap. +C#

    Question

  •  how can i rotate a bitmap image using C#
    algates
    Tuesday, July 07, 2009 6:30 AM

Answers

  • You create a new Bitmap, use the Graphics.FromImage method to get a Graphics object for drawing on it, set a rotation transform for the Graphics ojbect, and draw the original image using the DrawImage method.
    • Proposed as answer by Matthew Watson Tuesday, July 07, 2009 9:25 AM
    • Marked as answer by Harry Zhu Monday, July 13, 2009 8:58 AM
    Tuesday, July 07, 2009 8:13 AM
  • you can use the following code to rotate the image

                Graphics g = this.CreateGraphics();
                Image img = Image.FromFile(@"C:\WINDOWS\Gone Fishing.bmp");
    
                Point originalPos = new Point(10, 50);
                g.DrawImage(img, originalPos);
    
                Point rotatedPos = new Point(200, 50);
                img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                g.DrawImage(img, rotatedPos);
    
    you can change the RotateFlipType enumerator to get all rotation and lipping directions :)
    • Proposed as answer by Maged.A.Farag Thursday, July 09, 2009 6:26 AM
    • Marked as answer by Harry Zhu Monday, July 13, 2009 8:58 AM
    Thursday, July 09, 2009 5:44 AM

All replies

  • You create a new Bitmap, use the Graphics.FromImage method to get a Graphics object for drawing on it, set a rotation transform for the Graphics ojbect, and draw the original image using the DrawImage method.
    • Proposed as answer by Matthew Watson Tuesday, July 07, 2009 9:25 AM
    • Marked as answer by Harry Zhu Monday, July 13, 2009 8:58 AM
    Tuesday, July 07, 2009 8:13 AM
  • you can use the following code to rotate the image

                Graphics g = this.CreateGraphics();
                Image img = Image.FromFile(@"C:\WINDOWS\Gone Fishing.bmp");
    
                Point originalPos = new Point(10, 50);
                g.DrawImage(img, originalPos);
    
                Point rotatedPos = new Point(200, 50);
                img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                g.DrawImage(img, rotatedPos);
    
    you can change the RotateFlipType enumerator to get all rotation and lipping directions :)
    • Proposed as answer by Maged.A.Farag Thursday, July 09, 2009 6:26 AM
    • Marked as answer by Harry Zhu Monday, July 13, 2009 8:58 AM
    Thursday, July 09, 2009 5:44 AM