Picture Resizer

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.
4 posts Page 1 of 1
Contributors
User avatar
hungryhounduk
VIP - Site Partner
VIP - Site Partner
Posts: 2870
Joined: Mon Jul 27, 2009 11:58 am

Picture Resizer
hungryhounduk
Hi All
After i asked CodenStuff to create a Tutorial for a Banner Creator, and he produced such a cool little program 8-) After looking at the codeing of his idea, I got the idea for this little app ;)

This is a Picture Resizer with Drag n Drop capabilities
You just Drag your Image you want to Convert onto the image
It will let You convert your images to Jpg, Exif, Gif, Wmf, Tiff, Bmp and Png image Formats
Once again this is a very Easy Program to Build/Code ;)

Image
Image


On the Form you will need

1 PictureBox
2 GroupBoxes
4 Textboxes
4 Labels
1 Combobox
2 Checkboxes
1 Button
1 MenuStrip (Optional) I have just added this to show a MessageBox with a bit of Info.

You add your Image File Extentions (jpg,Gif ect) in the Combobox Collections in the Combobox Properties
Set your Picture box = STRETCH IMAGE in the PictureBox Properties
I have added a checkBox to let you either keep the Program Open when you Convert your Image Or if you Uncheck it it will exit after it has Converted the Image, Also i have added another checkBox for Keeping the Forms Focus OnTop of all other forms or Uncheck it to let other programs you have open to have Focus.

Enjoy :)

Chris

If you have any Problem then please send me a message and i wil talk you through it.


Code: Select all
Public Class Form1
    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)
                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

    Private Sub HowToUseThePictureResizerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 

HowToUseThePictureResizerToolStripMenuItem.Click
        MsgBox(" Drag and Drop your image, Type in your desired size, Choose your file extention Set your new size to Convert too and Click resize, Bmp, Png, Gif, Exif, Jpeg, Wmf, Tiff, Formats supported")
    End Sub
End Class
Hi All
Just a slight update to the Picture Resizer
With the Inclusion of 2 Checkboxe's which open and close the Controls and the Image Window ;)
And when you click on them to uncheck them they close the appropriate Item.
What you get when it loads up
Image
Controls and Image Window Open
Image
Image Window Closed with the Controls Open
Image



Chris
Image
User avatar
Martin
Supreme VIP
Supreme VIP
Posts: 369
Joined: Sat Aug 01, 2009 12:26 pm

Re: Picture Resizer
Martin
This tut Is Good
Image
User avatar
CodemaN
VIP Access - Denied
VIP Access - Denied
Posts: 74
Joined: Fri Sep 18, 2009 3:18 pm

Re: Picture Resizer
CodemaN
thanksssssssssss!!!!!!!!!!!!!!!!! coollllllllllllllllllll
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Re: Picture Resizer
Usman55
Hello There!

That was cool! Maybe you can add the feature to resize it without disturbing its pixels like if it is 48*48, then it will not become 32*98, it will become 32*32! Don't you remember this function in mspaint?

Thanks!
Image
4 posts Page 1 of 1
Return to “Tutorials”