Make a Picture Converter in VB 2008
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
Hi there,
I tried to make a pic converter and after spending 4 hours i got it...
Today i am going to show how to make a Picture Converter
You Need
2 Buttons ( Button 1 "Open File" Button 2 "Convert To")
1 ComboBox ( Add PNG JPEG GIF BMP ICO)
1 Label
1 Picture Box
1 OpenFileDialog
1 SaveFileDialog
Now add the Following Code to Open File Button
Regards
Shahbaz Singh
I tried to make a pic converter and after spending 4 hours i got it...
Today i am going to show how to make a Picture Converter
You Need
2 Buttons ( Button 1 "Open File" Button 2 "Convert To")
1 ComboBox ( Add PNG JPEG GIF BMP ICO)
1 Label
1 Picture Box
1 OpenFileDialog
1 SaveFileDialog
Now add the Following Code to Open File Button
Code: Select all
Now Add the Following Code to Convert to ButtonPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
PictureBox1.Image = System.Drawing.Image.FromFile(OpenFileDialog1.FileName)
End If
Catch ex As Exception
End Try
End Sub
Code: Select all
Hope You Got it..If ComboBox1.SelectedItem = "JPEG" Then
SaveFileDialog1.Filter = "JPEG |*.jpg"
Try
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
PictureBox1.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
End If
Catch ex As Exception
End Try
End If
Try
If ComboBox1.SelectedItem = "ICO" Then
SaveFileDialog1.Filter = "ICO |*.ico"
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
PictureBox1.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Icon)
End If
End If
Catch ex As Exception
End Try
If ComboBox1.SelectedItem = "PNG" Then
SaveFileDialog1.Filter = "PNG |*.png"
Try
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
PictureBox1.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Png)
End If
Catch ex As Exception
End Try
End If
If ComboBox1.SelectedItem = "GIF" Then
SaveFileDialog1.Filter = "GIF |*.gif"
Try
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
PictureBox1.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Gif)
End If
Catch ex As Exception
End Try
End If
If ComboBox1.SelectedItem = "BMP" Then
SaveFileDialog1.Filter = "BMP |*.bmp"
Try
If SaveFileDialog1.ShowDialog = DialogResult.OK Then
PictureBox1.Image.Save(SaveFileDialog1.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
End If
Catch ex As Exception
End Try
End If
End Sub
Regards
Shahbaz Singh
You could probably clean up the save part a bit:
Code: Select all
SaveFileDialog1.Filter = "JPEG|*.jpg|ICO|*.ico|PNG|*.png|GIF|*.gif|BMP|*.bmp"
Dim dr As DialogResult = SaveFileDialog1.ShowDialog()
If dr = Windows.Forms.DialogResult.OK Then
Dim fmt As Imaging.ImageFormat
If SaveFileDialog1.FilterIndex = 0 Then
fmt = System.Drawing.Imaging.ImageFormat.Jpeg
ElseIf SaveFileDialog1.FilterIndex = 1 Then
fmt = System.Drawing.Imaging.ImageFormat.Icon
ElseIf SaveFileDialog1.FilterIndex = 2 Then
fmt = System.Drawing.Imaging.ImageFormat.Png
ElseIf SaveFileDialog1.FilterIndex = 3 Then
fmt = System.Drawing.Imaging.ImageFormat.Gif
Else 'only bmp left
fmt = System.Drawing.Imaging.ImageFormat.Bmp
End If
Try
PictureBox1.Image.Save(SaveFileDialog1.FileName, fmt)
Catch ex As Exception
End Try
End If
Nice job, most of these converters i see on the net just change the extension without actually doing anything else
Visit BW Photography and check out my photos!
4 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023