locked
GetThumbnailImage is not resizing the image when saved RRS feed

  • Question

  • User644139582 posted
    The section of code I am having trouble with is below: 
     
    Dim originalpath As String = (Server.MapPath("~/uploads/"))
                    Dim strThumbPath As String = Server.MapPath("/thumbs/")
                    Dim originalname As String = FileUpload1.FileName
    
                    'load original image
                    Dim myimg As System.Drawing.Image
                    myimg = System.Drawing.Image.FromFile(originalpath & originalname)
    
                    Dim newwidth As Integer = 100
                    Dim newheight As Integer = 100
    
    
                    'size the thumbnail
                    myimg.GetThumbnailImage(newwidth, newheight, Nothing, New IntPtr())
    
                    'save the thumbnail
                    myimg.Save(Server.MapPath("~/thumbs/thumb_") & originalname)

     

    The file is saved in the correct folder with the correct name, but it has not been resized. Any thoughts as to why?


    Monday, December 27, 2010 1:48 PM

Answers

  • User-158764254 posted

    GetThumbnailImage returns a new image that you need to save.  You were just resaving the original.

    Try it like this:

    Dim thumb As System.Drawing.Image = myimg.GetThumbnailImage(newwidth, newheight, Nothing, New IntPtr())
    thumb.Save(Server.MapPath("~/thumbs/thumb_") & originalname)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 27, 2010 1:58 PM

All replies

  • User-158764254 posted

    GetThumbnailImage returns a new image that you need to save.  You were just resaving the original.

    Try it like this:

    Dim thumb As System.Drawing.Image = myimg.GetThumbnailImage(newwidth, newheight, Nothing, New IntPtr())
    thumb.Save(Server.MapPath("~/thumbs/thumb_") & originalname)

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 27, 2010 1:58 PM
  • User644139582 posted

    Thank you for the help!!

    As a side note, I like your avatar of the avatar. :)  

    Monday, December 27, 2010 2:44 PM