MANG KANOR
MANG KANOR

Reputation: 44

Converting JPEG to PNG in VB.NET(Saved output has no extension)

This is my code in converting my image

Public Sub ConvertImage(ByVal Filename As String, _
      ByVal DesiredFormat As System.Drawing.Imaging.ImageFormat, _
      ByVal NewFilename As String)
        NewFilename = "ConvertedToPNG-" + NewFilename + "-" + Format(Date.Now, "MMMMddyyyyhhmmtt")
        Try
            Dim imgFile As System.Drawing.Image = _
              System.Drawing.Image.FromFile(Filename)
            imgFile.Save(txtPNGFileDestination.Text & "\" & NewFilename, DesiredFormat)
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

It has runs properly but the saved image hasn't have a PNG file extension thus making it just a file. Am I doing anything wrong?

Thanks for your help

Upvotes: 1

Views: 4751

Answers (1)

SSS
SSS

Reputation: 5403

Just add the extension to NewFileName. You'll also need to declare NewFileName "ByRef":

Public Sub ConvertImage(ByVal Filename As String, ByVal DesiredFormat As System.Drawing.Imaging.ImageFormat, ByRef NewFilename As String)
  NewFilename = "ConvertedToPNG-" + NewFilename + "-" + Format(Date.Now, "MMMMddyyyyhhmmtt") & "." & DesiredFormat.ToString

Upvotes: 2

Related Questions