[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Use the Bitmap class's RotateFlip method to easily flip and rotate an image in C#

RotateFlip

The Bitmap class's RotateFlip method makes it easy to rotate an image by a multiple of 90 degrees and flip it vertically or horizontally. This example wraps the call to RotateFlip in the following ModifiedBitmap method. It makes a copy of an image, rotates and flips the copy, and returns the result.

// Copy the bitmap, rotate it, and return the result. private Bitmap ModifiedBitmap(Image original_image, RotateFlipType rotate_flip_type) { // Copy the Bitmap. Bitmap new_bitmap = new Bitmap(original_image); // Rotate and flip. new_bitmap.RotateFlip(rotate_flip_type); // Return the result. return new_bitmap; }

The following code shows how the program calls this method to rotate the image 180 degrees and then flip it horizontally:

private void rad270FlipX_CheckedChanged(object sender, EventArgs e) { picResult.Image = ModifiedBitmap( picOriginal.Image, RotateFlipType.Rotate270FlipX); }

After rotating or flipping a Bitmap, you can use its Save method to save the result into a file.

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.