Newsgroup: it.comp.www.asp
Titolo: Come salvare immagine jpg

Ciao a tutti,
ho trovato su internet uno script FREE chiamato resize.aspx che mi fa un
resize "al volo" di una immagine e me la visualizza a schermo.
La mia domanda č: come posso salvare l'immagine "ripicciolita" in un file,
invece di ottenerne solo la visualizzazione?
Allego qui sotto il codice INTERO dello script.
(lo script viene chiamato da un altro file con l'url
<img src="resize.aspx?src=img/dream.jpg&w=352&h=288">
quindi passandogli la dimensione che si vuole dell'immagine)
Spero di avere un vostro aiuto
Grazie mille
<%@ 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(request("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.imageformat.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.windowtext,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
%>

 Grazie mille
Sostituisci, o aggiuni, questa linea di codice:
dim nomefile as string=Request.MapPath("nomefile.jpg")
imgOutput.save(nomefile, imageformat.jpeg) ' output to the user
Se ho capito bene quello che volevi... :)
Ciao
--
AZ [Microsoft .NET MVP]