locked
image.save problem RRS feed

  • Question

  • User903612104 posted
     Public Function ResizeAndSave(ByVal ImagePath As String, ByVal SavePath As String, ByVal FileName As String,
                                      ByVal xWidth As Int32, ByVal yHeight As Int32) As Boolean
            Dim bm As Bitmap
            Dim x As Int32 = xWidth
            Dim y As Int32 = yHeight
            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)
            Try
                Using images As New Bitmap(ImagePath)
                    Using ms As New MemoryStream()
                        images.Save(ms, System.Drawing.Imaging.ImageFormat.Png)
                        bm = Image.FromStream(ms)
                        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()
                        thumb.Save(Server.MapPath(SavePath) + FileName)
                        bm.Dispose()
                        thumb.Dispose()
                    End Using
                End Using
            Catch ex As Exception
                Throw New Execption(ex.Message)
            End Try
            Return True
        End Function

    It is working when I debugging in local.

    But when I put it in the server, I get this error message"System.Exception: Parameter is not valid."
    How to fix this issue?

    Tuesday, August 4, 2015 12:23 AM

Answers

  • User-821857111 posted

    Try

    thumb.Save(Path.Combine(Server.MapPath(SavePath), FileName))

    If that doesn't fix things, show which line raises the error and the actual values of the variable involved (not what you think they should be, but what they actually are).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 4, 2015 2:10 AM

All replies

  • User-821857111 posted

    Try

    thumb.Save(Path.Combine(Server.MapPath(SavePath), FileName))

    If that doesn't fix things, show which line raises the error and the actual values of the variable involved (not what you think they should be, but what they actually are).

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, August 4, 2015 2:10 AM
  • User903612104 posted

    It's working.

    Thanks..Smile

    Monday, August 17, 2015 10:04 PM