Kavitha
Kavitha

Reputation: 69

Rotate Image using RotateFlip in C#

I have this code to rotate an image in an if loop in C# Windows Form application, but the Form does not show anything in the form output.

Can anyone help?

this.splitContainer1.Panel2.Controls.Add(PictureBox1);
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
PictureBox1.Image = bitmap; //Image.FromFile(@"C:\image.jpg");
PictureBox1.SizeMode = PictureBoxSizeMode.AutoSize;
PictureBox1.Image = (Image)(RotateImg(bitmap, 30.0f, Color.Transparent));

Upvotes: 4

Views: 13232

Answers (2)

Hessy SharpSabre
Hessy SharpSabre

Reputation: 152

Try this:

PictureBox1.Images.RotateFlip(RotateFlipType.Rotate180FlipX);
PictureBox1.Refresh();

Upvotes: 3

Gregor Primar
Gregor Primar

Reputation: 6805

if you need to rotate an image on common angles you can use RotateFlip method with ease. Please see my sample code:

string fileName = "somefile.png";
System.Drawing.Imaging.ImageFormat imageFormat = System.Drawing.Imaging.ImageFormat.Png;
Bitmap bitmap =(Bitmap)Bitmap.FromFile(fileName );
//this will rotate image to the left...
bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
//lets save result back to file...
bitmap.Save(fileName, imageFormat);
bitmap.Dispose();

That's all, hope it helps.

Upvotes: 6

Related Questions