Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2001
    Messaggi
    271

    resize e salvataggio sul server

    Ciao a tutti, ho trovato questo script per fare il resize delle immagini al volo.

    Ora pero' vorrei utilizzarlo per ridimensionare e salvare le immagini in precedenza uploadate.


    codice:
    <%@ Import Namespace="System.Drawing"%>
    <%@ Import Namespace="System.Drawing.Imaging"%>
    <SCRIPT RUNAT="SERVER">
    Sub Page_Load()
    
    	Dim width as Integer = 0
    	Dim height as Integer = 0
    
    	try
    		' ricava dimensioni dalla richiesta
    		if not Request.QueryString("width") is Nothing Then
    			width = Int32.Parse(Request.QueryString("width"))
    		End if
    		if not Request.QueryString("height") is Nothing Then
    			height = Int32.Parse(Request.QueryString("height"))
    		End if
    
    	catch ex as Exception
    	End Try
    
    	' ridimensiona l'immagine se specificato
    	
    	Dim immagine as String = Server.MapPath(Request("img"))
    	
    	
    	if Not System.Io.File.Exists(immagine) then
    		immagine = Server.MapPath("/immagini/nondisponibile.jpg")
    	end if
    
    	call ImgRedim(immagine, width, height)
    
    	' fermo il resto della risposta
    	Response.End()
    	End Sub
    
    ' Funzione di redim
    Public Sub ImgRedim(immagine as String, width as Integer, height as Integer)
    	Dim bmp as System.Drawing.Bitmap = CType(System.Drawing.Image.FromFile(immagine), System.Drawing.Bitmap)
    
    	' c'è da ridimensionare?
    	if width>0 or height>0 then
    		' se è specificata solo la larghezza, calcola l'altezza
    		if height = 0 Then
    			height = Convert.ToInt32(width / bmp.Width * bmp.Height)
    		End if
    
    		' (e viceversa)
    		if width = 0 Then
    			width = Convert.ToInt32(height / bmp.Height * bmp.Width)
    		End if
    
    		' creo la Thumbnail con i parametri impostati
    		Dim miniaturabmp as New System.Drawing.Bitmap(bmp, width, height)
    
    		' salvo sullo stream di output
    		if immagine.EndsWith(".jpg") Then
    			miniaturabmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
    			
    	        else
    			miniaturabmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
    		end if
    
    		' pulizia
    		miniaturabmp.Dispose()
    	else
    		' salvo sullo stream di output
    		if immagine.EndsWith(".jpg") Then
    			bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
    		else
    			bmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
    		end if
    	end if
    
    	' pulizia finale
    	bmp.Dispose()
    
    End Sub
    
    </SCRIPT>


    Ho sostituito

    codice:
    miniaturabmp.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
    con

    codice:
    miniaturabmp.Save(immagine, System.Drawing.Imaging.ImageFormat.Jpeg)

    Ma non funziona. Mi sapete aiutare?

  2. #2
    Utente di HTML.it
    Registrato dal
    Jun 2001
    Messaggi
    271
    Ho provato ad usare un nome differente da quello dell'immagine originale per limmagine salvata e funziona correttamente.

    Sapete se e' possibile salvarla su se stessa oppure bisogna per forza salvarla con un altro nome?

  3. #3
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    4,127
    prima devi cancellare l'immagine originale.. e poi puoi sostituirla

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.