Rotate Image using RotateFlip in C#

前端 未结 2 1123
甜味超标
甜味超标 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.

提交回复
热议问题