Introduction
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.
- Add openFileDialog and saveFileDialog to the form.
- Use this filter for the openFileDialog and saveFileDialog: †JPEG File|*.jpg|GIF File|*.gif|PNG File|*.png|BMP File|*.bmp “
- Add 4 buttons (refer to above image). Name the buttons just like I’ve did in that image.
- Set the “Enabled†property for “Save†button to “Falseâ€. And set “Visible†to “False†for “RotateClockwise†and “RotateCounterclockwise†buttons.
- 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: