Image Editing Tool in VB.Net: Part 1

In this article we will learn to make a image editing tool with the help of In this image editing tool we include resizing image, cropping image,brightness and contrast in images,rotation and other various common image editing functionality.

First we learn that how to implement these functionality in image one by one. so first we need to learn that how to show an image in windows form? for this we can take a picturebox control, picturebox control able to load an image file format like bmp,gpeg,gif,tiff file also.

So let start with our first step.

tart a new windows application and add one splitcontainer, picturebox, menustrip, toolstrip on windows form.


Arrange controls on the form like this.


Now we need to open image on the form so we use open filedialog class for selecting image file.

Code File

Private Img As Image


Declare Img as object of Image class. Image class is the member of System.Drawing namespace, it is abstrat base class that provides functionality for raster images(bitmaps) and vector images(Metafile) descended classes.


use openfiledialog on OpenToolStripMenuItem_Click event


   Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click

        Dim Dlg As New OpenFileDialog

        Dlg.Filter = ""

        Dlg.Title = "Select image"

        If Dlg.ShowDialog = Windows.Forms.DialogResult.OK Then

            Img = Image.FromFile(Dlg.FileName)

'Image.FromFile(String) method creates an image from the specifed file, here dlg.Filename contains the name of the file from which  to create the image


        End If

    End Sub


      Private Sub LoadImage()

'we set the picturebox size according to image, we can get image width and height with the help of Image.Width and Image.height properties.


        Dim imgWidth As Integer = Img.Width

        Dim imghieght As Integer = Img.Height

        PictureBox1.Width = imgWidth

        PictureBox1.Height = imghieght

        PictureBox1.Image = Img


    End Sub


Suppose that your picturebox or image size is smaller than background panel than image will show in the corner of the panel in upperside and this is not professional look of showing image so we set the picturebox or image center location on panel.


After doing this image will always show in center of panel


    Private Sub PictureBoxLocation()

        Dim _x As Integer = 0

        Dim _y As Integer = 0

        If SplitContainer1.Panel1.Width > PictureBox1.Width Then

            _x = (SplitContainer1.Panel1.Width - PictureBox1.Width) \ 2

        End If

        If SplitContainer1.Panel1.Height > PictureBox1.Height Then

            _y = (SplitContainer1.Panel1.Height - PictureBox1.Height) \ 2

        End If

        PictureBox1.Location = New Point(_x, _y)

    End Sub


    Private Sub SplitContainer1_Panel1_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SplitContainer1.Panel1.Resize


    End Sub


You can try this code  for making image editing tool,in this article you learn that how to show image on form, in next article of this series describe to Resize image....thanks

Similar Articles