1

这是我转换图像的代码

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

它运行正常,但保存的图像没有 PNG 文件扩展名,因此它只是一个文件。我做错什么了吗?

谢谢你的帮助

4

1 回答 1

2

只需将扩展名添加到 NewFileName。您还需要声明 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
于 2012-11-28T05:06:04.377 回答