C# Programming > Drawing

C# Image Flip

c# image flip

Image Flipping

There are several ways to flip an image in C#.NET using just GDI+. Image flipping is done either with the Image class or the Graphics class.

Since many other sites describe the code that flips images with the Image class, this article covers image flipping with Graphics and Matrix classes.

Matrix Transform

The trick of flipping an image is similar to rotating a .NET image. The flip is handled via Matrix transformation. A matrix transformation is useful because developers can apply multiple image transformations at once.

This is important because flipping and image will move it outside the normal bounds, so the Matrix must also shift (or translate) the image back to the visible rectangle.

Another useful property of flipping an image with a Matrix is developers can simultaneously apply a horizontal and vertical flip. This is not to say other techniques can't do simultaneous flipping.

Rendering the Image

To display the image with the Graphics class you can use any normal DrawImage function. Since the Matrix transformation is applied directly to the Transform property, the class will automatically apply the transformation to all rendering operations.

As far as interpolation goes, since the image is the same size after being flipped, there is no interpolation done. Remember interpolation is a way to resample pixels when the image is being shrunk or enlarged. In other words, there is no need to worry about the SmoothingMode property.

Source Code

The sample application shows how to flip an image in C# with the technique described above.

Back to C# Article List