Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Immagini bloccate dopo il Resize

    Ciao a tutti.
    Premetto che non conosco nulla di ASP.net, ma provo ad utilizzare uno script per ridimensionare delle immagini trovato su questo forum. Lo script di per se funziona benissimo, ma poi non posso più accedere alle immagini "trattate", cioè non riesco a cancellarle o spostarle o semplicemente rinominarle. In locale mi appare una finestra che mi avvisa che il file in questione è in uso da un altro programma o da un altro utente e per risolvere termino il processo aspnet_wp.exe dal Task Manager, in remoto invece mi da un errore di accesso negato.
    Dove, ma soprattutto come posso modificare lo script affinchè tutto funzioni regolarmente??

    Grazie per l'attenzione.

    Posto lo script:
    codice:
    <%@ Page Language="C#" Debug="true" %>
    
    <%@ import Namespace="System"%>
    <%@ import Namespace="System.IO"%>
    <%@ import Namespace="System.Drawing" %>
    <%@ import Namespace="System.Drawing.Imaging" %>
    <%@ import Namespace="System.Text.RegularExpressions" %>
    
    
    <script Language="C#" runat="server">
    void Page_Load(Object sender, EventArgs e)
    {
      int ThumbnailWidth = 64;
    int ThumbnailHeight = 64;
    string strFileName = "";
    string destinazione = "./";
    
    double orgImgWidth = 0.0;
    double orgImgHeight = 0.0;
    double rThumbnailWidth = 0.0;
    double rThumbnailHeight = 0.0;
    
    System.Drawing.Image orgImage;
    
      if (Request.QueryString["w"] != "") ThumbnailWidth = Convert.ToInt32(Request.QueryString["w"]);
      if (Request.QueryString["h"] != "") ThumbnailHeight = Convert.ToInt32(Request.QueryString["h"]);
    
    if (Request.QueryString["src"] != "")
    {
    strFileName = Convert.ToString(Request.QueryString["src"]);
    
    if (Request.QueryString["percorso"] != "") destinazione = Convert.ToString(Server.MapPath(Request.QueryString["percorso"]));
    else 
     destinazione = Convert.ToString(Server.MapPath(destinazione));
    
    if (strFileName != "")
    {
      try
       {
    	  orgImage = System.Drawing.Image.FromFile(Server.MapPath(strFileName));
    		using(Bitmap tmpImage = new Bitmap(orgImage))
    		 {
    		  rThumbnailWidth = ThumbnailWidth;
    		  rThumbnailHeight = ThumbnailHeight;
    		  orgImgWidth = tmpImage.Width;
    		  orgImgHeight = tmpImage.Height;
    
    			  // Se l'immagine è più piccola del Thumbnail forziamo le dimensioni di 
    			  // quest'ultimo alle dimensioni dell'immagine.
    			  if (orgImgWidth < ThumbnailWidth) ThumbnailWidth = tmpImage.Width;
    			  if (orgImgHeight < ThumbnailHeight) ThumbnailHeight = tmpImage.Height;
    			  // Se le dimensioni dell'immagine e del Thumbnail corrispondono non facciamo nulla.
    			  if (tmpImage.Width != tmpImage.Height)
    		   {
    				// Altrimenti continuiamo a fare i nostri controlli per calcolarne le 
    				// giuste dimensioni e quindi creare la nostra nuova immagine con
    				// l'aspectratio corretto.
    			if (tmpImage.Width > tmpImage.Height)
    			 {
    			  // L > H => tH = (H * tL)/ L
    			  rThumbnailWidth = ThumbnailWidth;
    			  rThumbnailHeight = (double)((tmpImage.Height * ThumbnailWidth) / tmpImage.Width);
    			 } // if (tmpImage.Width > tmpImage.Height)
    		    else
    			 {
    			  if (tmpImage.Width < tmpImage.Height)
    			   {
    			    // L < H => tL = (L * tH)/ H
    			    rThumbnailHeight = ThumbnailWidth;
    			    rThumbnailWidth = (double)((tmpImage.Width * ThumbnailHeight) / tmpImage.Height);
    			   } // if (tmpImage.Width < tmpImage.Height)
    			 } // else
    		   } // if (tmpImage.Width != tmpImage.Height)
    		 } // using(Bitmap tmpImage = new Bitmap(orgImage))
    
    	   using(Bitmap bitmap = new Bitmap(orgImage, (int)(rThumbnailWidth), (int)(rThumbnailHeight)))
    		{
    			 Response.ContentType = orgImage.RawFormat.ToString();
    			 Response.Clear();
    			 Response.BufferOutput = true;
    			 Response.AddHeader("Content-Disposition", "filename=" + strFileName);
    
    			 // In questo caso viene creata e salvata la Thumbnail dell'immagine in /thumbs/
    			 if ((orgImage.Width > ThumbnailWidth) || (orgImage.Height > ThumbnailHeight)) 
    		  { 
    		   bitmap.Save(Response.OutputStream, orgImage.RawFormat);
    		   bitmap.Save(destinazione + "/public/" + strFileName, orgImage.RawFormat);
    		  } // if ((orgImage.Width > ThumbnailWidth) || (orgImage.Height > ThumbnailHeight))
    		 else // L'immagine rientra già nella dimensione da noi decisa quindi non serve creargli il Thumbnail.
    		  {
    		   bitmap.Save(Response.OutputStream, orgImage.RawFormat);
    		  } // else
             Response.Flush();
    		} // using(Bitmap bitmap = new Bitmap(orgImage, (int)(rThumbnailWidth), (int)(rThumbnailHeight)))
       } // try
      catch (Exception ex)
       {
    	Response.Write(ex.Message);
       } // catch (Exception ex)
      finally
       {
        Response.Write("\nRe-Coded by R.B. Riddick");
       	
       }
     } // if (strFileName != "")
    } // if (Request.QueryString["src"] != "")
    }
    </script>

  2. #2
    Bisogna sempre rilasciare le risorse una volta completate tutte le operazioni.
    Non ho guardato bene il codice, ma probabilmente qualche oggetto aperto non viene chiuso correttamente (rilasciando risorse tramite .Dispose()).

  3. #3
    Ok, risolto!!
    Trovato la soluzione nel forum dopo una nottata di ricerche.
    Grazie!!

    Qui per chi fosse interessato.

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.