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