Salve amici,,
ho una pagina asp che fa un upload ed alla fine ho il nome del file caricato. vorrei che cliccando sull'immagine si potesse ridimensionare il file salvandolo nuovamente. Ho cercato ed ho trovato questo script:
<%@ Page Language="VB" ContentType="text/html"%>
<script language="vb" runat="server">
Sub Page_Load(Server as Object,e as System.EventArgs)
Dim redimFoto as String = Request.Querystring("foto")
Dim RedimSizeThumb as integer = CInt(Request.QueryString("foto"))
Dim RedimSizeFoto as integer = CInt(Request.QueryString("foto"))
ReDimImg("" & redimFoto ,"" & RedimFoto,RedimSizeThumb,0)
ReDimImg("" & redimFoto ,"" & RedimFoto,RedimSizeFoto,0)
End Sub
Public Sub ReDimImg(SourcePath as String,ResizeName as string, width as integer,height as integer)
Try
'Creo l'oggetto di riferimento al file originale
Dim TmpBmp as System.Drawing.Bitmap = CType(System.Drawing.Image.FromFile(Server.MapPath (SourcePath)), System.Drawing.Bitmap)
Dim newWidth,newHeight as string
'Se il parametro height è lasciato a 0 costruisco il with in maniera proporzionata
if height = 0 Then
newHeight = Convert.ToInt32(width / TmpBmp.Width * TmpBmp.Height)
else
newHeight = height
End if
'Se il parametro with è lasciato a 0 costruisco l'height in maniera proporzionata
if width = 0 Then
newWidth = Convert.ToInt32(height / TmpBmp.Height * TmpBmp.Width)
else
newWidth = width
end if
'Creo la miniatura con lunghezza e larghezza elaborati
Dim miniaturabmp as New System.Drawing.Bitmap(TmpBmp, newWidth, newHeight)
'Distruggo l'oggetto dell'immagine originale che non mi serve +
TmpBmp.Dispose()
'controllo l'estensione e salvo la miniatura nel giusto formato
if SourcePath.toLower().EndsWith(".jpg") or SourcePath.toLower().EndsWith(".jpeg") Then
miniaturabmp.Save(Server.MapPath(ResizeName), System.Drawing.Imaging.ImageFormat.Jpeg)
elseif SourcePath.toLower().EndsWith(".gif") Then
miniaturabmp.Save(Server.MapPath(ResizeName), System.Drawing.Imaging.ImageFormat.Gif)
elseif SourcePath.toLower().EndsWith(".png") Then
miniaturabmp.Save(Server.MapPath(ResizeName), System.Drawing.Imaging.ImageFormat.Png)
else
Response.Write("Errore Formato")
'Si puo' ampliare l'elseif in questo modo:
'elseif SourcePath.toLower().EndsWith(".[Estensione]") Then
'miniaturabmp.Save(Server.MapPath(ResizeName), System.Drawing.Imaging.ImageFormat.[Estensione])
'dove [Estensione] puo essere Bmp, Emf, Exif, Tiff, Wmf
end if
miniaturabmp.Dispose()
Catch ex as System.Exception
'Nel caso stampo l'errore:
Response.Write("<hr>Errore nel ridimensionamento dell'immagine:
" & ex.Message & "
")
Response.Write("
" & ex.StackTrace & "<hr>")
End Try
Response.Write("Ridimensionamento effettuato con successo")
End Sub
</script>
però non so come adattarlo! Qualcuno saprebbe aiutarmi?
Ho provato associando un link tipo:
ridimensiona.aspx?foto=nomefilecaricato
ma non va

Rispondi quotando