Friday, February 2, 2007

Display image in a Web Page

I 've took a lot of times to surf the web to find out the best resolution to display image and scale image with the best quality.

1. Scale image by .NET to produce the best quality
Dim fileName As String = albumlist.SelectedValue & "_" & currentDate & fileExtension
' Create image object from upload stream
Dim img As System.Drawing.Bitmap = System.Drawing.Bitmap.FromStream(.InputStream)
Dim imageFormat = img.RawFormat

Dim thumbSize As New Size
thumbSize = NewthumbSize(img.Width, img.Height)
'Thumb-nail the image to the new size
Dim imgOutput As New Bitmap(img, thumbSize.Width, thumbSize.Height)

'**************THIS HAD TO BE ADDED!!*****************
Dim myresizer As Graphics
myresizer = Graphics.FromImage(imgOutput)
myresizer.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
myresizer.DrawImage(img, 0, 0, thumbSize.Width, thumbSize.Height)
'****************************************************

'Save original image
imgOutput.Save(Path.Combine(Server.MapPath("../photo/images"), fileName), imageFormat)

Note the bold code above, It will produces the best quality image when you try to Zoom or Scale to smaller image.

Beside, I found another way to scale smaller image but, using CSS and HTML only. THe quality is good.

No comments: