Page 1 of 1

How to make an Image Rotator

Posted: Tue Dec 07, 2010 6:16 pm
by Usman55
Hello everyone,

Here is another tutorial that I am posting today. This tutorial shows how to make an image rotator that has like 16 rotation types (all the rotations that the system/vb.net supports). You can load an image, rotate it and then save it while keeping the rotation. Please don't post negative/disappointing comments.

---------------------------------------------------------------------------

First of all, open Visual Basic 2008, create a new project, choose Windows Forms Application, type in the textbox Image Rotator and press the OK button. As soon as you have done this, the Form1 will appear on the screen on which we will design our application and code it.


First we will do the designing and then the coding. So now we will change the Form1's properties to make it look good. Change the Form1's Text property to Image Rotator. Change it's StartPosition property to CenterScreen. Change it's FormBorderStyle to FixedSingle. Change it's MaximizeBox property to False. Change it's Size property to 500, 350 or whatever you like, no restrictions!


Now add the following things to the form:

(1)_ 1 PictureBox. Change it's SizeMode property to Zoom. Change it's BorderStyle property to FixedSingle.

(2)_ 3 Buttons. Change Button1's Text property to Open, Button2's to Save and Button3's to Rotate.

(3)_ 1 ComboBox. Add the following items to it by clicking on its Items property and then click on the "..." button. Here are the items:
Code: Select all
Rotate180FlipNone
Rotate180FlipX
Rotate180FlipXY
Rotate180FlipY
Rotate270FlipNone
Rotate270FlipX
Rotate270FlipXY
Rotate270FlipY
Rotate90FlipNone
Rotate90FlipX
Rotate90FlipXY
Rotate90FlipY
RotateNoneFlipNone
RotateNoneFlipX
RotateNoneFlipXY
RotateNoneFlipY

Now is the time to code Form1 and it's components. So right-click on the form in the Solution Explorer and click View Code.

Type the following code before Public Class Form1:
Code: Select all
Imports System.Drawing.Imaging
Write the following code by double-clicking Button1 whose Text property was Open:
Code: Select all
Dim opendlg As OpenFileDialog = New OpenFileDialog()
        opendlg.Title = "Select the image to open."
        opendlg.Filter = ("Supported Image Files|*.gif;*.jpg;*.bmp;*.png")
        opendlg.ShowDialog()
        Dim Image As Image = New Bitmap(opendlg.FileName)
        PictureBox1.Image = Image
Write the following code by double-clicking Button2 whose Text property was Save:
Code: Select all
Dim savedlg As New SaveFileDialog
        savedlg.Title = "Select the filename to save the image."
        savedlg.Filter = ("Supported Image Files|*.gif;*.jpg;*.bmp;*.png")
        Dim pic As Image
        pic = PictureBox1.Image
        savedlg.ShowDialog()
        pic.Save(savedlg.FileName)
Write the following code by double-clicking Button3 whose Text property was Rotate:
Code: Select all
Dim rotateImage As Image = New Bitmap(PictureBox1.Image)
        If ComboBox1.Text = "Rotate180FlipNone" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate180FlipNone)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate180FlipX" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate180FlipX)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate180FlipXY" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate180FlipXY)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate180FlipY" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate180FlipY)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate270FlipNone" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate270FlipNone)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate270FlipX" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate270FlipX)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate270FlipXY" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate270FlipXY)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate270FlipY" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate270FlipY)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate90FlipNone" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate90FlipNone)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate90FlipX" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate90FlipX)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate90FlipXY" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate90FlipXY)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "Rotate90FlipY" Then
            rotateImage.RotateFlip(RotateFlipType.Rotate90FlipY)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "RotateNoneFlipNone" Then
            rotateImage.RotateFlip(RotateFlipType.RotateNoneFlipNone)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "RotateNoneFlipX" Then
            rotateImage.RotateFlip(RotateFlipType.RotateNoneFlipX)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "RotateNoneFlipXY" Then
            rotateImage.RotateFlip(RotateFlipType.RotateNoneFlipXY)
            PictureBox1.Image = rotateImage
        ElseIf ComboBox1.Text = "RotateNoneFlipY" Then
            rotateImage.RotateFlip(RotateFlipType.RotateNoneFlipY)
            PictureBox1.Image = rotateImage
        End If

Well, that's all. It was real easy, wasn't it?

---------------------------------------------------------------------------

Voila! You have just completed making an Image Rotator rotates the image that you provide by 16 rotation types. Now debug and run it by pressing the Start Debugging button located at the main toolstrip. Test it, if it works fine then its SAVING time. You can save your project by going to File -> Save All and then pressing Save.

And there! You have your project and application that works. If you have any problem or can't understand something, please feel free to ask by either a comment or by PM. I have also attached a screenshot.

Please use the Give Thanks button and the Reputation System to appreciate my hard work. I have wrote this tutorial while making an Image Rotator project myself so you can download the source file in the attachments.

Thank you.

Image

Re: How to make an Image Rotator

Posted: Tue Dec 07, 2010 6:23 pm
by Axel
switch case would be alooot easyer :P

and shouldn't it be Combobox1.selecteditem ?

Re: How to make an Image Rotator

Posted: Tue Dec 07, 2010 6:29 pm
by MrAksel
YourSocksRoxx wrote:
switch case would be alooot easyer :P
Switch case is C#, its Select Case in VB :lol:
Anyway, good tutorial for people that wanna make image editors

Re: How to make an Image Rotator

Posted: Tue Dec 07, 2010 6:34 pm
by Axel
MrAksel wrote:
YourSocksRoxx wrote:
switch case would be alooot easyer :P
Switch case is C#, its Select Case in VB :lol:
Anyway, good tutorial for people that wanna make image editors
oops my bad :P thx for tellin

Re: How to make an Image Rotator

Posted: Tue Dec 07, 2010 6:41 pm
by Usman55
Hello there,

Selecting cases is a difficult job for me. I'm a straight way programmer you know. Instead of this, can you please tell how did you like it?

Thank you.

Re: How to make an Image Rotator

Posted: Tue Dec 07, 2010 6:56 pm
by Axel
Usman55 wrote:
Hello there,

Selecting cases is a difficult job for me. I'm a straight way programmer you know. Instead of this, can you please tell how did you like it?

Thank you.
its not hard :|

just
select case combobox1.selecteditem
case "Rotateblabla"
'do this
case "Rotate20554"
' do smtn else
case .......
end select

Re: How to make an Image Rotator

Posted: Tue Dec 07, 2010 7:53 pm
by CleverBoy
lol today you make a little app Rotator
now you post a tut about it
great job i like you tuts
thanks cooll;

Re: How to make an Image Rotator

Posted: Tue Dec 07, 2010 9:27 pm
by mandai
You can also use Graphics.Transform.RotateAt to rotate at a set point for any number of angles.

Re: How to make an Image Rotator

Posted: Wed Dec 08, 2010 11:16 am
by Usman55
Anyways, I'm not going to update it for a long time I guess.