private void Form1_Load(object sender, EventArgs e) { Image img = pictureBox1.Image; RotateImage(img, 45); } public static Image RotateImage(Image img, float rotationAngle) { //create an empty Bitmap image Bitmap bmp = new Bitmap(img.Width, img.Height); //turn the Bitmap into a Graphics object Graphics gfx = Graphics.FromImage(img); //gfx.Clear(Color.Transparent); //now we set the rotation point to the center of our image gfx.TranslateTransform((float)img.Width / 2, (float)img.Height / 2); //now rotate the image gfx.RotateTransform(rotationAngle); gfx.TranslateTransform(-(float)img.Width / 2, -(float)img.Height / 2); //set the InterpolationMode to HighQualityBicubic so to ensure a high //quality image once it is transformed to the specified size gfx.InterpolationMode = InterpolationMode.HighQualityBicubic; //gfx.Clear(Color.White); //now draw our new image onto the graphics object gfx.DrawImage(img, new Point(0, 0)); //dispose of our Graphics object gfx.Dispose(); //return the image return img; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)