Losing picture qaulity when resizing on the fly! RRS feed

  • Question

  • User944361798 posted

    I am resizing an image from (1024 X 768) to (450 X 338), but losing so much picture qaulity, because of the image becoming blurry!

    Anything I can do better to hold the image qaulity when resizing the image? 

    Thank you for any help in advance!

    Dim objImage, objThumbnail As Image

    Dim shtWidth, shtHeight As Short

    objImage = objImage.FromFile(Server.MapPath("/Template/images/" & FileName))

    thisFormat = objImage.RawFormat

    ' set width

    shtWidth = 150

    ' Work out a proportionate height from width

    shtHeight = objImage.Height / (objImage.Width / shtWidth)

    ' Create thumbnail

    objThumbnail = objImage.GetThumbnailImage(shtWidth, shtHeight, Nothing, System.IntPtr.Zero)

    ' Send down to client

    objThumbnail.Save(Server.MapPath("/Template/images/thumbnails/") & FileName, thisFormat)

    ' Tidy up



    Thursday, June 16, 2005 7:09 AM

All replies

  • User1152494133 posted
    Don't trust the GetThumbnailImage() for anything other than, well, small thumbnails (i.e., it works great for images around 150px, no so great for things around 450px).  Create a new image of the smaller dimensions (450x338) and draw the original image to the new image with scaling.

    I posted some sample code here: http://forums.asp.net/958348/ShowPost.aspx
    Thursday, June 16, 2005 8:44 AM
  • User944361798 posted

    Great! Thanks Jason, it works just fine, here is my (your) solution :)

    Dim Pic As Image = Image.FromFile(Server.MapPath("/Template/images/" & FileName))

    Dim thisFormat = Pic.RawFormat

    Dim ImageWidht As Integer = 450

    Dim ImageHeight As Integer = Pic.Height / (Pic.Width / ImageWidht)

    Dim NewPic As Bitmap = New Bitmap(ImageWidht, ImageHeight)

    Dim Gr As Graphics = Graphics.FromImage(NewPic)

    Gr.DrawImage(Pic, 0, 0, ImageWidht, ImageHeight)

    NewPic.Save(Server.MapPath("/Template/images/normal/") & FileName, thisFormat)




    Thursday, June 16, 2005 7:57 PM