Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 423

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/session/session.php on line 426

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/e/r/ferasferas1/html/scriptslibrary/libraries/joomla/database/database.php:2) in /home/content/f/e/r/ferasferas1/html/scriptslibrary/templates/ja_purity/ja_templatetools.php on line 49
Convert BMP Images to Other Types in VB.NET - The Scripts Library Community

Free Programming Tutorials & Source Code

 
  • Increase font size
  • Default font size
  • Decrease font size
Home Visual Basic.NET Convert BMP Images to Other Types in VB.NET

Convert BMP Images to Other Types in VB.NET

E-mail
(0 votes, average: 0 out of 5)
This example demonstrates how to convert BMP files to other image types. it uses the IO and Drawing library.
First, create a new form, switch to View Code mode, and inset these namespaces at the top of your document:


Imports System.Drawing.Imaging
Imports System.IO.Path

Switch back to the View Design mode, and add the following controls:
TextBox, name it as txtOriginal.
Button, name is as btnOpen
Butoon, name is as btnConvert
ListBox, name is as lbox
OpenFileDialog, name it as file

Add these items to the lbox ListBox:
Emf
Exif
Gif
Icon
MemoryBmp
Png
Tiff
Wmf

Add two labels as shown in the picture below.

image convertor

Back to the View Code mode, add the following code:


    Public Function ConvertImage(ByVal path As String, _
     ByVal format As ImageFormat) As Boolean

        Dim flag As Boolean
        Dim nFile As String

        Try
            ' create Bitmap variable to hold the old image
            Dim vImage As New Bitmap(path)

            ' set new file directory name
            nFile = GetDirectoryName(path)
            'parse the file name without the extension
            nFile &= "\" & GetFileNameWithoutExtension(path)
            'add new extension to file
            nFile &= "." & format.ToString
            ' save the file
            vImage.Save(nFile, format)

            flag = True
        Catch ex As Exception
            MsgBox(ex.Message)

            flag = False
        End Try
        Return flag

    End Function


btnOpen Click Event:


Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
 file.ShowDialog()
End Sub


File FileOk Event:

Private Sub file_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles file.FileOk
 Me.txtOriginal.Text = file.FileName
End Sub


btnConvert Click Event:


    Private Sub btnConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConvert.Click
        Try
            Select Case Me.lbox.SelectedItem
                Case "Emf"
                    ConvertImage(Me.txtOriginal.Text, ImageFormat.Emf)
                Case "Exif"
                    ConvertImage(txtOriginal.Text, ImageFormat.Exif)
                Case "Gif"
                    ConvertImage(txtOriginal.Text, ImageFormat.Gif)
                Case "Jpeg"
                    ConvertImage(txtOriginal.Text, ImageFormat.Jpeg)
                Case "Icon"
                    ConvertImage(txtOriginal.Text, ImageFormat.Icon)
                Case "MemoryBmp"
                    ConvertImage(txtOriginal.Text, ImageFormat.MemoryBmp)
                Case "Png"
                    ConvertImage(txtOriginal.Text, ImageFormat.Png)
                Case "Tiff"
                    ConvertImage(txtOriginal.Text, ImageFormat.Tiff)
                Case "Wmf"
                    ConvertImage(txtOriginal.Text, ImageFormat.Wmf)
            End Select
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Sub
        End Try
        MsgBox("Image successfully converted")
    End Sub

Happy coding!