billeder bliver grynede / uklare (web)
Hej.Jeg bruger nedenstående kode til at resize billeder 'on the fly', men hvor bliver de så uklare?
<%@Import Namespace="System.Drawing.Imaging" %>
<script language="VB" runat="server">
Function ThumbnailCallback() as Boolean
Return False
End Function
Sub Page_Load(sender as Object, e as EventArgs)
'Read in the image filename to create a thumbnail of
Dim imageUrl as String = Request.QueryString("img")
'Read in the width and height
Dim imageHeight as Integer = Request.QueryString("h")
Dim imageWidth as Integer = Request.QueryString("w")
'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 \
'Response.End()
'End If
'Add on the appropriate directory
Dim fullSizeImg As System.Drawing.Image = System.Drawing.Image.FromFile(Server.MapPath(imageUrl))
'Do we need to create a thumbnail?
Response.ContentType = "image/jpeg"
If imageHeight > 0 And imageWidth > 0 Then
Dim thumbNailImg As System.Drawing.Bitmap
thumbNailImg = Me.ResizeBitmapWidth(fullSizeImg, imageWidth)
thumbNailImg.Save(Response.OutputStream, ImageFormat.Jpeg)
Else
fullSizeImg.Save(Response.OutputStream, ImageFormat.Jpeg)
End If
End Sub
Private Function ResizeBitmapWidth(ByVal pSourceBitmap As Drawing.Bitmap, _
ByVal pNewWidth As Int32) As Drawing.Bitmap
Dim lNewHeight As Int32
lNewHeight = CType(pSourceBitmap.Height * (pNewWidth / pSourceBitmap.Width), Int32)
Dim lResizedBitmap As New Drawing.Bitmap(pNewWidth, lNewHeight)
Dim lGraphics As Drawing.Graphics = Drawing.Graphics.FromImage(lResizedBitmap)
lGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic
lGraphics.DrawImage(pSourceBitmap, 0, 0, pNewWidth, lNewHeight)
Return lResizedBitmap
End Function
</script>