Visualizzazione dei risultati da 1 a 10 su 10

Discussione: Resize immagine KO

  1. #1

    Resize immagine KO

    sto' utilizzando uno script aspx che ridimensiona sul server le immagini prima di caricarle sul client, al fine di ottimizzare i tempi di caricamento della pagina

    Il problema che mi si pone e' che funziona SOLO SE
    Altezza < Larghezza
    anche di un solo pixel

    come mai ?
    guarda questa pagina
    http://www.erlupacchiotto.com/prova/Foto/FotoRedim.html
    solo la foto di dx viene caricata, quella al centro invece no

    grazie a tutti anticipatamente

    -------redim.html----------
    PROVA FOTO 90*90
    [img]resize.aspx?src=Foto4.jpg&w=150&h=150[/img]
    PROVA FOTO 90*89
    [img]resize.aspx?src=Foto5.jpg&w=150&h=150[/img]

    -------resize.aspx----------
    <%@ import namespace="System" %>
    <%@ import namespace="System.Drawing" %>
    <%@ import namespace="System.Drawing.Imaging" %>
    <%@ import namespace="System.IO" %>

    <script runat="server">

    Function NewthumbSize(currentwidth, currentheight)


    ' Calculate the Size of the New image




    dim k,a,b,c,d as Double

    k=currentwidth/currentheight

    a=currentwidth
    b=currentheight
    c=Request.QueryString("h")
    d=Request.QueryString("w")



    'if (k<=1 and currentheight>=c) then
    'a=c*k
    'b=c
    'end if

    if (k>1) then

    a=d
    b=d/k

    else

    a=c*k
    b=c

    end if




    dim NewSize as New Size(a, b)








    return NewSize

    End Function


    Sub sendFile()

    ' create New image and bitmap objects. Load the image file and put into a resized bitmap.
    dim g as System.Drawing.Image = System.Drawing.Image.FromFile(server.mappath(reque st("src")))
    'dim g as System.Drawing.Image = System.Drawing.Image.FromFile(request("src"))






    ' initialise the web object
    'Dim webC As New System.Net.WebClient()

    ' set the URL
    'Dim strFilename as string

    'if Request.QueryString("src")="" then
    ' strFilename="http://127.0.0.1/chiave.jpg"
    'else
    ' strFilename="http://127.0.0.1/thumbaspx/"&Request.QueryString("src")
    'end if

    ' create a bitmap based on the image from the URL
    'Dim g = New System.Drawing.Bitmap(webC.OpenRead(strFilename))










    dim thisFormat=g.rawformat

    dim thumbSize as New size
    thumbSize=NewthumbSize(g.width,g.height)

    dim imgOutput as New Bitmap(g, thumbSize.width, thumbSize.height)

    ' Set the contenttype

    'if thisformat.equals(system.drawing.imaging.imageform at.Gif) then
    'response.contenttype="image/gif"
    'else
    response.contenttype="image/jpeg"
    'end if



    ' send the resized image to the viewer
    imgOutput.save(response.outputstream, thisformat) ' output to the user

    ' tidy up
    g.dispose()
    imgOutput.dispose()

    end sub

    Sub sendError()

    ' if no height, width, src then output "error"
    dim imgOutput as New bitmap(120, 120, pixelformat.format24bpprgb)
    dim g as graphics = graphics.fromimage(imgOutput)
    'create a New graphic object from the above bmp
    g.clear(color.yellow) ' blank the image
    g.drawString("ERRORE!", New font("verdana",14,fontstyle.bold),systembrushes.wi ndowtext,new pointF(2,2))

    ' Set the contenttype
    response.contenttype="image/jpeg"

    ' send the resized image to the viewer
    imgOutput.save(response.outputstream, imageformat.jpeg) ' output to the user

    ' tidy up
    g.dispose()
    imgOutput.dispose()


    end sub


    </script>



    <%


    ' make sure Nothing has gone to the client
    response.clear


    if request("src")="" then

    call sendError()

    else

    if file.exists(server.mappath(request("src"))) then
    call sendFile()
    else
    call sendError()
    end if

    end if


    response.end

    %>

  2. #2
    nessuno puo' aiutarmi a risolvere il problema ?
    :-(
    grazie
    ciao a tutti

  3. #3
    codice:
    If imgw > imgh Then
       newimgw = width
       newimgh = (imgh * width) / imgw
    ElseIf imgh > imgw Then
       newimgw = high
       newimgh = (imgh * high) / imgw
    Else
        newimgw = width
        newimgh = high
    End If

    dove imgw e imgh sono quelle relative alla tua immagine.
    e dove high e width sono quelle che tu scegli per il ridimensionamento.

    Questo codice è una semplice proporzione.

  4. #4
    Scusami, questo che segue e' il codice che ho, saresti cosi' gentile da dirmi dove lo devo mettere ?
    grazie
    *----------------------------------*
    Function NewthumbSize(currentwidth, currentheight)

    ' Calculate the Size of the New image
    dim k,a,b,c,d as Double

    k=currentwidth/currentheight

    a=currentwidth
    b=currentheight
    c=Request.QueryString("h")
    d=Request.QueryString("w")

    if (k>1) then
    a=d
    b=d/k
    else
    a=c*k
    b=c
    end if

    dim NewSize as New Size(a, b)

    return NewSize

  5. #5
    spiegami quali sono i valori della tua immagine e quali sono quelli che tu prefissi per la nuova img.

  6. #6
    non ho valori di dimensioni fisse, e nemmeno di proporzioni, ossia a volte le img sono quadrate altre invece rettangolari

  7. #7
    senti io per ridimensionare le immagini, fisso sempre una dimensione es. 150*250 o 250*150

    se l'immagine che voglio ridimensionare è veritcale passo dei valori se è orizzonatale ne passo altri.

    Cmq credo che delle misure per ridimensionarle le devi passare.

  8. #8
    ok, mi e' chiaro
    w=400 h = 3000
    poi ?

  9. #9
    poi riprendi il codice che ti ho passato all'inizio.

    su imgw e imgh mettici i valori originali

    mentre su width e high mettici 400 e 300


    dopo di che avrai le misure nuove in newimgw e newimgh

  10. #10
    ok, ora mi e' chiaro ti ringrazio
    ciao

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.