Ciao a tutti!
stavo realizzando un'area di amministrazione dove si potranno caricare immagine che vengono ridimensionate in maniera automatica tramite questo script:
Il mio problema è che le immagini piccole vengono abbastanza male, avevo pensato di aggiungere una funziona che facesse il crop dell'immagine, oltre che il resize. Solo che quelle che ho provato non mi funzionano (sono abbastanza niubbo in materia), voi potresta aiutarmi?codice:Randomize() ' used to help the cache-busting on the preview images upload_ok = False If LCase(Request.ServerVariables("REQUEST_METHOD")) = "post" Then fileFld = Request.Files(0) ' get the first file uploaded from the form (note:- you can use this to itterate through more than one image) If fileFld.ContentLength > upload_max_size * 1024 Then msg = "L'immagine non deve superare: " & upload_max_size & "Kb" Else Try originalimg = System.Drawing.Image.FromStream(fileFld.InputStream) ' work out the width/height for the thumbnail. Preserve aspect ratio and honour max width/height ' Note: if the original is smaller than the thumbnail size it will be scaled up newHeight = 105 newWidth = 80 Dim thumb As New Bitmap(newWidth, newHeight) 'Create a graphics object Dim gr_dest As Graphics = Graphics.FromImage(thumb) ' just in case it's a transparent GIF force the bg to white Dim sb = New SolidBrush(System.Drawing.Color.White) gr_dest.FillRectangle(sb, 0, 0, thumb.Width, thumb.Height) 'Re-draw the image to the specified height and width gr_dest.DrawImage(originalimg, 0, 0, thumb.Width, thumb.Height) fileExt = System.IO.Path.GetExtension(fileFld.FileName).ToLower() originalimg.Save(Server.MapPath(upload_dir_main & upload_original & fileExt), originalimg.RawFormat) thumb.Save(Server.MapPath(upload_dir_thumb & upload_thumb & fileExt), originalimg.RawFormat) msg = "Immagine: " & fileFld.FileName & " Caricata in: " & Server.MapPath(upload_dir_main & upload_original & fileExt) upload_ok = True ' Housekeeping for the generated thumbnail If Not thumb Is Nothing Then thumb.Dispose() thumb = Nothing End If Catch msg = "Quest'immagine non può essere caricata." End Try End If ' House Keeping ! If Not originalimg Is Nothing Then originalimg.Dispose() originalimg = Nothing End If End If
GRAZIE!

Rispondi quotando