Article Options
Premium Sponsor
Premium Sponsor

 »  Home  »  .NET Newbie  »  A Simple Photo Browser  »  Basic Image Manipulation
 »  Home  »  Windows Development  »  A Simple Photo Browser  »  Basic Image Manipulation
 »  Home  »  Windows Development  »  Win Forms  »  A Simple Photo Browser  »  Basic Image Manipulation
A Simple Photo Browser
by Chris Mills | Published  04/14/2006 | .NET Newbie Windows Development Win Forms | Rating:
Basic Image Manipulation

We are now going to add the ability to perform basic image manipulation.  The .NET Framework image object contains a method that will flip and/or rotate the image it represents - this makes our job relatively easy. 

We'll add event handlers to respond to the options available in the image menu.  All of these event handlers check that an image is loaded, call the "RotateFlip" method the image object that represents the photo then calls the ReDrawPhoto function so that the modified image is displayed.  All functions pass coordinates of the centre of the image to the ReDrawPhoto function.  Add the following to your code:

    Private Sub ImageFlipVeritcal(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles mnuImageFlipVertical.Click
        If Not picPhoto.Image Is Nothing Then
            picPhoto.Image.RotateFlip(RotateFlipType.RotateNoneFlipX)
            ReDrawPhoto(CInt(pnlPhoto.Width / 2), CInt(pnlPhoto.Height / 2))
        End If
    End Sub

    Private Sub ImageFlipHorizontal(ByVal sender As System.Object, ByVal e As System.EventArgs) ) _
        Handles mnuImageFlipHorizontal.Click
        If Not picPhoto.Image Is Nothing Then
            picPhoto.Image.RotateFlip(RotateFlipType.RotateNoneFlipY)
            ReDrawPhoto(CInt(pnlPhoto.Width / 2), CInt(pnlPhoto.Height / 2))
        End If
    End Sub

    Private Sub ImageRotateLeft(ByVal sender As System.Object, ByVal e As System.EventArgs) ) _
        Handles mnuImageRotateLeft.Click
        If Not picPhoto.Image Is Nothing Then
            picPhoto.Image.RotateFlip(RotateFlipType.Rotate270FlipNone)
            ReDrawPhoto(CInt(pnlPhoto.Width / 2), CInt(pnlPhoto.Height / 2))
        End If
    End Sub

    Private Sub ImageRotateRight(ByVal sender As System.Object, ByVal e As System.EventArgs) ) _
        Handles mnuImageRotateRight.Click
        If Not picPhoto.Image Is Nothing Then
            picPhoto.Image.RotateFlip(RotateFlipType.Rotate90FlipNone)
            ReDrawPhoto(CInt(pnlPhoto.Width / 2), CInt(pnlPhoto.Height / 2))
        End If
    End Sub

In Visual Basic.NET event handlers can handle events from more than one source.  The "Handles" statements in all of the event handlers above could be extended to also handle events from another source, for example a toolbar or context menu.

Sponsored Links