Resizing images, image is much bigger in size

Last post 11-08-2009 10:08 AM by SGWellens. 1 replies.

Sort Posts:

  • Resizing images, image is much bigger in size

    11-08-2009, 8:22 AM
    • Member
      240 point Member
    • CzechMate
    • Member since 04-01-2005, 6:29 PM
    • Posts 60

    I'm using the function below to resize images. However when I take image that's say 35 KB's in size

    the resulting resized image is around 450 KB's in size. Why is this happening ? Is there a way to make compress the image again ? 

     

        Sub ResizeImage(ByVal IMAGE_PATH As String, ByVal IMAGE_SAVE_AS As String, ByVal maxWidth As Int32, ByVal maxHeight As Int32)
            Dim originalImage As New Drawing.Bitmap(IMAGE_PATH)
            Dim newWidth As Int32 = originalImage.Width
            Dim newHeight As Int32 = originalImage.Height
    
            Dim aspectRatio As Double = Double.Parse(originalImage.Width) / Double.Parse(originalImage.Height)
    
            If (aspectRatio <= 1 And originalImage.Width > maxWidth) Then
                newWidth = maxWidth
                newHeight = CInt(Math.Round(newWidth / aspectRatio))
            Else
                If (aspectRatio > 1 And originalImage.Height > maxHeight) Then
                    newHeight = maxHeight
                    newWidth = CInt(Math.Round(newHeight * aspectRatio))
                End If
            End If
    
            Dim newImage As New Drawing.Bitmap(originalImage, newWidth, newHeight)
            Dim g As Drawing.Graphics = Drawing.Graphics.FromImage(newImage)
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Default
            g.DrawImage(originalImage, 0, 0, newImage.Width, newImage.Height)
            originalImage.Dispose()
    
            newImage.Save(IMAGE_SAVE_AS)
            newImage.Dispose()
        End Sub


     

  • Re: Resizing images, image is much bigger in size

    11-08-2009, 10:08 AM
    Answer
    • All-Star
      91,294 point All-Star
    • SGWellens
    • Member since 01-02-2007, 9:27 PM
    • Twin Cities, MN
    • Posts 7,446
    • Moderator
      TrustedFriends-MVPs
    Steve Wellens

    My blog
Page 1 of 1 (2 items)