Avatar billede agerled Nybegynder
28. maj 2006 - 11:02

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>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester