Page 1 of 2

Picture Taker with many Features

Posted: Sun Dec 27, 2009 2:36 am
by RunarM
This is my first Visual Basic tutorial, so i hope you like it omg;

I'm going to show you how to make a Picture taker like this:
Image
Now, the first thing you might think is, "wow.. that sucks", well this it has many features as i said...
http://i700.photobucket.com/albums/ww4/ ... howxxl.png

Anyways here is the tutorial:

FORM 1

What you need:
*4 Buttons - name "B1 = "Capture Screen" - B2 = "Save Image" - B3 = "Watch Picture" - B4 = "New Picture".
*Picture box [Just hide it somewhere]

Full Code:
Code: Select all
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim bounds As Rectangle
        Dim screenshot As System.Drawing.Bitmap
        Dim graph As Graphics
        bounds = Screen.PrimaryScreen.Bounds
        screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
        graph = Graphics.FromImage(screenshot)
        graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
        PictureBox1.Image = screenshot
        Do Until Me.Height = 136
            Me.Height = Me.Height + 1
        Loop
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim savefiledialog1 As New SaveFileDialog
        Try
            savefiledialog1.Title = "Save Captured Image"
            savefiledialog1.FileName = "Screenshot Image 1"
            savefiledialog1.Filter = "All Type Of Image Files|*.*|Joint Photographic Experts Group [JPEG]|*.jpg|Bitmap [BMP|*.bmp|Tagged Image File Format [TIFF]|*.tiff|Portable Network Graphics [PNG]|*.png"
            If savefiledialog1.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
            End If
        Catch ex As Exception
        End Try
        Do Until Me.Height = 136
            Me.Height = Me.Height + 1
        Loop
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Form2.Show()
        Do Until Me.Height = 85
            Me.Height = Me.Height - 1
        Loop
    End Sub


    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Do Until Me.Height = 59
            Me.Height = Me.Height - 1
        Loop
    End Sub

End Class
OR THE SAME ONLY SINGLED:

Button 1:
Code: Select all
        Dim bounds As Rectangle
        Dim screenshot As System.Drawing.Bitmap
        Dim graph As Graphics
        bounds = Screen.PrimaryScreen.Bounds
        screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
        graph = Graphics.FromImage(screenshot)
        graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
        PictureBox1.Image = screenshot
        Do Until Me.Height = 136
            Me.Height = Me.Height + 1
        Loop
Button 2:
Code: Select all
        Dim savefiledialog1 As New SaveFileDialog
        Try
            savefiledialog1.Title = "Save Captured Image"
            savefiledialog1.FileName = "Screenshot Image 1"
            savefiledialog1.Filter = "All Type Of Image Files|*.*|Joint Photographic Experts Group [JPEG]|*.jpg|Bitmap [BMP|*.bmp|Tagged Image File Format [TIFF]|*.tiff|Portable Network Graphics [PNG]|*.png"
            If savefiledialog1.ShowDialog() = DialogResult.OK Then
                PictureBox1.Image.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
            End If
        Catch ex As Exception
        End Try
        Do Until Me.Height = 136
            Me.Height = Me.Height + 1
        Loop
Button 3:
Code: Select all
        Form2.Show()
        Do Until Me.Height = 85
            Me.Height = Me.Height - 1
        Loop
Button 4:
Code: Select all
        Do Until Me.Height = 59
            Me.Height = Me.Height - 1
        Loop


NOW form 2:

What you need:
*3 Buttons - Name: [B1 = "Open Image Folder" - B2 = "Open Single Image" - B3 = "Picture Resize".
*Label
*List box
*Picture box

Full code:
Code: Select all
 Public Class Form2

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FolderBrowserDialog1.ShowDialog()
        Dim fold As New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
        Dim foldi As IO.FileInfo() = fold.GetFiles("*.jpg")
        Dim foldg As IO.FileInfo
        Label1.Text = FolderBrowserDialog1.SelectedPath
        ListBox1.Items.Clear()
        For Each foldg In foldi
            ListBox1.Items.Add(foldg)
        Next
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        OpenFileDialog1.FileName = "Select a Image file"
        OpenFileDialog1.Filter = "All Type Of Image Files|*.*|Joint Photographic Experts Group [JPEG]|*.jpg|Bitmap [BMP|*.bmp|Tagged Image File Format [TIFF]|*.tiff|Portable Network Graphics [PNG]|*.png"
        If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            PictureBox1.Image = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)
            PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        End If
    End Sub

    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        Dim Pfolder
        Dim Pname
        Try
            Pfolder = Label1.Text
            Pname = ListBox1.SelectedItem.ToString
            PictureBox1.Image = System.Drawing.Image.FromFile(Pfolder + "\" + Pname)
            PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        Catch ex As Exception
            MsgBox("You have to select an Image Folder first")
        End Try
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Form3.Show()
    End Sub
End Class 
OR THE SAME ONLY SINGLED:

Button 1:
Code: Select all
        FolderBrowserDialog1.ShowDialog()
        Dim fold As New IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
        Dim foldi As IO.FileInfo() = fold.GetFiles("*.jpg")
        Dim foldg As IO.FileInfo
        Label1.Text = FolderBrowserDialog1.SelectedPath
        ListBox1.Items.Clear()
        For Each foldg In foldi
            ListBox1.Items.Add(foldg)
        Next
Button 2:
Code: Select all
 OpenFileDialog1.FileName = "Select a Image file"
        OpenFileDialog1.Filter = "All Type Of Image Files|*.*|Joint Photographic Experts Group [JPEG]|*.jpg|Bitmap [BMP|*.bmp|Tagged Image File Format [TIFF]|*.tiff|Portable Network Graphics [PNG]|*.png"
        If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
            PictureBox1.Image = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)
            PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        End If
Listbox1:
Code: Select all
        Dim Pfolder
        Dim Pname
        Try
            Pfolder = Label1.Text
            Pname = ListBox1.SelectedItem.ToString
            PictureBox1.Image = System.Drawing.Image.FromFile(Pfolder + "\" + Pname)
            PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
        Catch ex As Exception
            MsgBox("You have to select an Image Folder first")
        End Try
Button 3:
Code: Select all
        Form3.Show()

FORM 3:

What you need:
*Picture Box
*4 Text Box
*2 Group Box
*2 Checkbox
*1 Button named "Resize Image"
*Combo Box

FULL CODE:
Code: Select all
 Public Class Form3
    Dim hhound() As String
    Dim int As String
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureBox1.AllowDrop = True
    End Sub


    Private Sub PictureBox1_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragDrop
        Try
            Dim hhound() As String
            Dim int As String
            If e.Data.GetDataPresent(DataFormats.FileDrop) Then
                hhound = e.Data.GetData(DataFormats.FileDrop)
                int = hhound(0)
                PictureBox1.Image = Image.FromFile(int)
                PictureBox1.SizeMode = PictureBoxSizeMode.Zoom
                TextBox3.Text = PictureBox1.Image.Width
                TextBox4.Text = PictureBox1.Image.Height
            End If
        Catch
            MsgBox("Cannot copy your picture")
        End Try
    End Sub

    Private Sub PictureBox1_DragEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles PictureBox1.DragEnter
        e.Effect = e.AllowedEffect
    End Sub



    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim str As String
            Dim savefiledialog1 As New SaveFileDialog()
            Dim bm As New Bitmap(PictureBox1.Image)
            Dim x As Int32 = TextBox1.Text
            Dim y As Int32 = TextBox2.Text
            str = ComboBox1.SelectedItem
            Dim width As Integer = Val(x)
            Dim height As Integer = Val(y)
            Dim thumb As New Bitmap(width, height)
            Dim g As Graphics = Graphics.FromImage(thumb)
            g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
            g.DrawImage(bm, New Rectangle(0, 0, width, height), New Rectangle(0, 0, bm.Width, bm.Height), GraphicsUnit.Pixel)
            g.Dispose()
            savefiledialog1.Filter = str + "|*." + str
            savefiledialog1.ShowDialog()
            If str = "Wmf" Then
                thumb.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Wmf)
                bm.Dispose()
                thumb.Dispose()
            ElseIf str = "gif" Then
                thumb.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Gif)
                bm.Dispose()
                thumb.Dispose()
            ElseIf str = "exif" Then
                thumb.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Exif)
                bm.Dispose()
                thumb.Dispose()
            ElseIf str = "jpeg" Then
                thumb.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
                bm.Dispose()
                thumb.Dispose()
            ElseIf str = "tiff" Then
                thumb.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Tiff)
                bm.Dispose()
                thumb.Dispose()
            ElseIf str = "Bmp" Then
                thumb.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
                bm.Dispose()
                thumb.Dispose()
            ElseIf str = "png" Then
                thumb.Save(savefiledialog1.FileName, System.Drawing.Imaging.ImageFormat.Png)
                bm.Dispose()
                thumb.Dispose()
            End If
            MsgBox("Resize successfully!")
            If CheckBox2.Checked = True Then
                Me.Close()
            End If
        Catch
            MsgBox("Cannot convert your picture")
        End Try
    End Sub



    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        If CheckBox1.Checked = True Then
            Me.TopMost = True
        Else
            Me.TopMost = False
        End If
    End Sub


    Private Sub CheckBox2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox2.CheckedChanged

    End Sub

End Class



Thanks for reading clapper;
Here you can download the Project :

Re: Picture Taker with many Features

Posted: Sun Dec 27, 2009 2:56 am
by Toxikr3
oh DANG.

Thats nice! Good job!

Re: Picture Taker with many Features

Posted: Sun Dec 27, 2009 4:08 am
by CodenStuff
Hello RunarM,

Great job on this one I like the simple interface.

Keep it up cooll;

Re: Picture Taker with many Features

Posted: Fri Jan 01, 2010 8:17 pm
by RunarM
Anyone else liked it =)?

Re: Picture Taker with many Features

Posted: Wed Jan 06, 2010 4:53 pm
by Usman55
Well, this is very nice and I hope that you add more features in it!
Thanks!

Re: Picture Taker with many Features

Posted: Thu Jan 07, 2010 4:02 am
by RunarM
lmao;

Re: Picture Taker with many Features

Posted: Thu Jan 07, 2010 7:23 pm
by hungryhounduk
Hi
Very nice cooll;
I like the simplicity of it, and it works really well cooll;

Well Done

Chris

Re: Picture Taker with many Features

Posted: Sun Nov 28, 2010 2:28 am
by Livengood
Very nice :D, nice tutorial there :D

Re: Picture Taker with many Features

Posted: Sun Nov 28, 2010 2:41 am
by Agust1337
LOL your first tutorial :D? Gratzie, but anyways, it looks nice ;) Really good and explained tutorial cooll;

Re: Picture Taker with many Features

Posted: Sun Nov 28, 2010 11:38 am
by NecroPhis
omg nice tutorial :O keep it up