Rotate or Flip images in C# .NET

While working with images, you may often need to flip images programmatically. Depending upon the scenarios, you may want to flip images vertically or horizontally. In this article, you will learn how to flip images programmatically in C#. You can easily use this feature in your .NET image processing or editing applications.

C# API to Flip Images - Free Download

To flip images from within .NET applications, we will use Aspose.Imaging for .NET. It is an image processing API that provides a wide range of features to manipulate various types of images. Furthermore, it hides the complex operations and makes it quite easier for you to perform image processing. You can download the API or install it into your .NET applications using NuGet.

PM> Install-Package Aspose.Imaging

Steps to Flip an Image in C#

Using Aspose.Imaging, you can easily flip the images horizontally or vertically. For this, the API provides RotateFlipType enum to specify the flip type (and/or rotation angle). You can perform the following flip/rotate operations on an image:

  • Rotate only
  • Flip only
  • Both rotate and flip

The following are the steps to flip an image in C#.

  • Load the image from the disk.
  • Flip image to desired direction.
  • Save the updated image on disk.

Let’s write the C# code for the above-mentioned steps and see how to flip the following image.

Image for rotation and flipping

Flip an Image in C#

To flip an image, the following RotateFlipType members are used.

  • RotateNoneFlipX: No rotation with horizontal flipping
  • RotateNoneFlipY: No rotation with vertical flipping
  • RotateNoneFlipXY: No rotation with horizontal and vertical flipping

The following are the steps to flip an image in C#.

The following code sample shows how to flip an image in .NET applications.

The following screenshot shows how the image is flipped using the code snippet above.

Flip an image in C#

Flip an Image

Rotate and Flip an Image in C#

In this section, we will see how to rotate and flip the image at the same time. To achieve this, the following members of RotateFlipType enum are used.

  • Rotate180FlipX: 180-degree rotation with horizontal flipping
  • Rotate180FlipXY: 180-degree rotation with horizontal and vertical flipping
  • Rotate180FlipY: 180-degree rotation with vertical flipping
  • Rotate270FlipX: 270-degree rotation with horizontal flipping
  • Rotate270FlipXY: 270-degree rotation with horizontal and vertical flipping
  • Rotate270FlipY: 270-degree rotation with vertical flipping
  • Rotate90FlipX: 90-degree rotation with horizontal flipping
  • Rotate90FlipXY: 90-degree rotation with horizontal and vertical flipping
  • Rotate90FlipY: 90-degree rotation with vertical flipping

The following are the steps to rotate and flip an image in C#.

The following C# code snippet shows how to perform rotation and flipping at the same time.

The following screenshot shows how the image looks like after we apply rotation and flipping.

Rotate and flip an image in C#

Rotate and Flip an Image

C# Image Flipping API - Get a Free License

You can get a free temporary license and flip images horizontally and vertically without evaluation limitations.

Conclusion

In this article, you have learned how to flip images programmatically in C#. Furthermore, the step by step guide and code samples have demonstrated how to flip an image and rotate and flip an image at the same time. Besides, you can explore more about .NET image processing API using documentation. Also, you can download the source code samples of the API from GitHub. In case of any queries, you can reach us at our forum.

See Also