Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Resized Thumbnail

Status
Not open for further replies.

MarkZK

Technical User
Jul 13, 2006
202
GB
Hi all,

I used "NoCoolHandle"'s code from this thread ...


which does work, but can anyone tell me why the thumbnails being made are around five time bigger (in file size) than the original, it's VERY odd!.

test.jpg 640x480 - 38KB
test_thumb.jpg 320x240 - 168KB

Code:
			'Create Thumbnail
			    Dim thumbnail As System.Drawing.Image
				Dim image As System.Drawing.Image = System.Drawing.Image.FromFile(path)
				thumbnail = ScaleImage(image, 320, 240)
				thumbnail.Save(Server.MapPath(AppPath & "/Images/Thumbs/" & imgName & "_thumb.jpg"))



function..

Code:
    Function ScaleImage(ByVal imgFull As Image, ByVal intX As Integer, ByVal intY As Integer) As Image

        Dim dblScaleFactor As Double
        Dim dblScaleX, dblScaleY As Double

        dblScaleX = intX / imgFull.Width
        dblScaleY = intY / imgFull.Height

        If dblScaleX > dblScaleY Then
            dblScaleFactor = dblScaleX
        Else
            dblScaleFactor = dblScaleY
        End If

        Dim scale_factor As Single = CType(dblScaleFactor, Single)

        Dim imgBMP_dest As New Bitmap(CInt(imgFull.Width * scale_factor), CInt(imgFull.Height * scale_factor))

        Dim imgOutput As Graphics = Graphics.FromImage(imgBMP_dest)
        imgOutput.DrawImage(imgFull, 0, 0, imgBMP_dest.Width + 1, imgBMP_dest.Height + 1)

        imgOutput.Dispose()
        imgOutput = Nothing

        Return imgBMP_dest

    End Function

Am I doing something wrong ?, is there a better way to keep some quality and get a smaller file size ?...

Any ideas would be great, thanks.
 

I'll answer my own question :) .... it shoud have been..

Code:
thumbnail.Save(Server.MapPath(AppPath & "/Images/Thumbs/" & imgName & "_thumb.jpg"), System.Drawing.Imaging.ImageFormat.Jpeg)

I guess it wasn't compressing the image to a jpg file, I also missed some cleaning up (.Dispose())
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top