How to make an Image Rotator

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
9 posts Page 1 of 1
Contributors
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

How to make an Image Rotator
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
You do not have the required permissions to view the files attached to this post.
Image
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: How to make an Image Rotator
Axel
switch case would be alooot easyer :P

and shouldn't it be Combobox1.selecteditem ?
http://vagex.com/?ref=25000
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

Re: How to make an Image Rotator
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
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: How to make an Image Rotator
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
http://vagex.com/?ref=25000
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: How to make an Image Rotator
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.
Image
User avatar
Axel
Coding God
Coding God
Posts: 1928
Joined: Sun Jun 27, 2010 9:15 pm

Re: How to make an Image Rotator
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
http://vagex.com/?ref=25000
User avatar
CleverBoy
VIP - Donator
VIP - Donator
Posts: 395
Joined: Mon Dec 06, 2010 8:29 pm

Re: How to make an Image Rotator
CleverBoy
lol today you make a little app Rotator
now you post a tut about it
great job i like you tuts
thanks cooll;
Code'N'Stuff
OneTeam..OneDream
Join ABSplash Team & Earn $$
ABSplash Site - Workpad - (VB) Custom Buttons 2 ways
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Re: How to make an Image Rotator
mandai
You can also use Graphics.Transform.RotateAt to rotate at a set point for any number of angles.
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: How to make an Image Rotator
Usman55
Anyways, I'm not going to update it for a long time I guess.
Image
9 posts Page 1 of 1
Return to “Tutorials”