Rotate Image using RotateFlip in C#

前端 未结 2 1124
甜味超标
甜味超标 2021-01-20 07:51

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?

         


        
相关标签:
2条回答
  • 2021-01-20 08:40

    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.

    0 讨论(0)
  • 2021-01-20 08:44

    Try this:

    PictureBox1.Images.RotateFlip(RotateFlipType.Rotate180FlipX);
    PictureBox1.Refresh();
    
    0 讨论(0)
提交回复
热议问题