Image Viewer application using C#

A detailed tutorial about creating an Image Viewer or Picture Viewer application in C#. This application also converts images from one type to another.

Following are the features of this application:

  • Open / Save images.
  • Convert images.
  • Rotate Images.
  • All popular image formats are supported.

Let’s get started!

Setting up the Designer

For this application you will need an openFileDialog, saveFileDialog, pictureBox and a few buttons.

  1. Add openFileDialog and saveFileDialog to the form.
  2. Use this filter for the openFileDialog and saveFileDialog: ” JPEG File|*.jpg|GIF File|*.gif|PNG File|*.png|BMP File|*.bmp “
  3. Add 4 buttons (refer to the image above). Name the buttons just like I’ve did in that image.
  4. Set the “Enabled” property for “Save” button to “False”. And set “Visible” to “False” for “RotateClockwise” and “RotateCounterclockwise” buttons.
  5. Add a pictureBox and place it under the buttons (refer to the image above).

That’s it. Now lets get on with the code.

The Code

First of all, add this code to the very top of your form:

Declare these methods after the “public Form1() { ….” method:

Double-click the “Open” button to add the “Click()” event for it and use this code:

Double-click the Save button and use this code:

Double-click the RotateClockwise button and use this code:

And lastly, double-click the Rotate Counterclockwise button and use this code:

That’s it! We are done.

Source Code

ImageViewer Source – Download Now (42 Kb)

Leave a Reply

Your email address will not be published. Required fields are marked *