Akhil Joshi
How to rotate an Image in C#?
By Akhil Joshi in Windows Forms on Oct 04 2012
  • Dhaval Rathod
    Aug, 2020 4
  • Rajanikant Hawaldar
    Oct, 2022 13

    1. public static Image RotateImage(Image img, float rotationAngle)
    2. {
    3. //create an empty Bitmap image
    4. Bitmap bmp = new Bitmap(img.Width, img.Height);
    5. //turn the Bitmap into a Graphics object
    6. Graphics gfx = Graphics.FromImage(bmp);
    7. //now we set the rotation point to the center of our image
    8. gfx.TranslateTransform((float)bmp.Width / 2, (float)bmp.Height / 2);
    9. //now rotate the image
    10. gfx.RotateTransform(rotationAngle);
    11. gfx.TranslateTransform(-(float)bmp.Width / 2, -(float)bmp.Height / 2);
    12. //set the InterpolationMode to HighQualityBicubic so to ensure a high
    13. //quality image once it is transformed to the specified size
    14. gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
    15. //now draw our new image onto the graphics object
    16. gfx.DrawImage(img, new Point(0, 0));
    17. //dispose of our Graphics object
    18. gfx.Dispose();
    19. //return the image
    20. return bmp;
    21. }

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS