Possible Duplicate:
Resize image on the fly make the image lose quality online but locally works nice
I wrote this handler to resize images on the fly:
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
'Read in the image filename to create a thumbnail of
Dim imageUrl As String = context.Request.QueryString("img")
'Make sure that the image URL doesn't contain any /'s or \'s
If imageUrl.IndexOf("/") >= 0 Or imageUrl.IndexOf("\") >= 0 Then
'We found a / or \
context.Response.End()
End If
'Get the image.
Dim fullSizeImg As System.Drawing.Image
'fullSizeImg = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
fullSizeImg = System.Drawing.Image.FromFile(imageUrl)
Dim smallImage As System.Drawing.Image
'Resize the image
smallImage = DynamicImage.Resize(fullSizeImg, 225, 225, True)
'Set the ContentType to "image/jpg" and output the image's data
context.Response.ContentType = "image/jpg"
' Create an Encoder object based on the GUID
' for the Quality parameter category.
Dim myEncoder As System.Drawing.Imaging.Encoder = System.Drawing.Imaging.Encoder.Quality
' Create an EncoderParameters object.
' An EncoderParameters object has an array of EncoderParameter
' objects. In this case, there is only one
' EncoderParameter object in the array.
Dim myEncoderParameters As New EncoderParameters(1)
Dim myEncoderParameter As New EncoderParameter(myEncoder, 100&)
myEncoderParameters.Param(0) = myEncoderParameter
Dim jgpEncoder As ImageCodecInfo = GetEncoder(ImageFormat.Jpeg)
smallImage.Save(context.Response.OutputStream, jgpEncoder, myEncoderParameters)
'Dispose/clean up...
smallImage.Dispose()
fullSizeImg.Dispose()
End Sub
My problem is that this code return a good quality image on my local server but when i put online the image lose quality.
I tested this code on 2 different servers one with IIS6 and another with IIS7 but the same low quality happen.
What may be the reason of this strange issue? in which direction should i think?