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

    eliminare con asp una immagine dal server, utilizzata da asp.net

    Ciao a tutti: questa problematica si pone a cavallo fra ASP e ASP.NET...

    In pratica ho una pagina ASP nella quale vengono create e visualizzate in tempo reale alcune miniature, utilizzando uno script ASPX+C# che ho trovato qui:

    http://www.imente.org/index.php/deve...sses/wbresize/

    Nella pagina sono inoltre presenti dei pulsanti per eliminare, mediante un banale script asp, le immagini relative - grandi - dal server.

    Il mio problema è che non riesco ad eliminare le immagini: cioè è come se queste fossero costantemente 'impegnate' dal server e da asp.net per creare le relative miniature...per cui mi da sempre e comunque 'permesso negato'

    In pratica, da quanto ho capito frugando nel codice C#, lo script che crea le miniature utilizza una memorystream...che dunque andrebbe (penso) chiusa prima di eliminare l'immagine. Qualcuno sa come posso risolvere??
    Where there is a will, there is a way

  2. #2
    credo che questa sia più una problematica .net

    in ogni caso al termine dello script c#

    metti queste 2 righe:

    ImageResizer.UnloadImage();
    ImageResizer = null;

    dovrebbe fungere
    Non ho paura dei miei pensieri, ma ho paura ad esprimerli.
    La libertà d'espressione oggi, potrebbe diventare prigionia del corpo domani.

  3. #3
    ...fungere già funge...infatti mi fa sparire le miniature

    A me ovviamente mi serve visualizzarle... ed eventualmente chiuderle prima di eliminare le foto dal server...ma come??
    Where there is a will, there is a way

  4. #4
    se posti il codice della pagina che dovrebbe visualizzare le foto, vediamo che si po' fà

    considera che non conosco minimamente il componente in questione, quindi se ci sono include che ritieni siano rilevanti posta anche quelli...

    ora vado a nanna domani se qualcuno non ti ha già aiutato provo a cimentarmi.

    Non ho paura dei miei pensieri, ma ho paura ad esprimerli.
    La libertà d'espressione oggi, potrebbe diventare prigionia del corpo domani.

  5. #5
    codice che richiama la creazione di una miniatura:
    codice:
    Response.write("[img][/img]")
    codice (scremato del non essenziale) della pagina creamin.aspx:
    codice:
    <%@ import Namespace="System.Drawing" %>
    <%@ import Namespace="System.Drawing.Imaging" %>
    <%@ Import Namespace="System.IO" %> 
    <%@ Import Namespace="System.Drawing.Drawing2D" %> 
    
    <script Language="C#" runat="server" src="wbresize/wbresize.cs"></script>
    
    <script Language="C#" runat="server">
    
    
    
    
    string ThumbType = "jpg";
    
    void Page_Load(object sender, System.EventArgs e)
    {	
    	
    	
    	
    	
    		// RICEVIAMO NELL'URL: img, w, h, fn
    		//
    		// img: percorso esatto dell'immagine
    		// w: larghezza massima che dovrà avere l'immagine ridimensionata
    		// h: altezza massima che dovrà avere l'immagine ridimensionata
    		// fn: tipo di ridimensionamento
    	
    
    		if (Request.QueryString["img"] == null) return;
    
    		string imgName = Convert.ToString(Request.QueryString["img"]);
    		if (imgName == "") return;
    		
    		// a questo punto, imgName = img = percorso in cui si trova l'immagine da ridimensionare
    
    	
    	
    
    		string func = "";
    		if (Request.QueryString["fn"] != null) func = Convert.ToString(Request.QueryString["fn"]);
    		if (func != "g" && func != "z" && func != "a") func = "l";
    		
    		// a questo punto, func = fn = g, z, a oppure l
    
    
    
    		// ZoomX di default = 100%, oppure larghezza massima/larghezza assoluta di default = 150 pixel
    		float resize_w = (func == "z") ? 100 : 150;
    		if (Request.QueryString["w"] != null) resize_w = Convert.ToSingle(Request.QueryString["w"]);
    
    		// ZoomY di default = ZoomX, oppure altezza massima/altezza assoluta di default = 100 pixel
    		float resize_h = (func == "z") ? resize_w : 100;
    		if (Request.QueryString["h"] != null) resize_h = Convert.ToSingle(Request.QueryString["h"]);
    		
    		// a questo punto, resize_w e resize_h mi dicono che larghezza-altezza massima dovrà avere la mia foto
    
    
    
    		// Carica l'immagine originale e ottieni le sue dimensioni
    		System.Drawing.Image origImage = System.Drawing.Image.FromFile(Server.MapPath(imgName));
    		int w = origImage.Width;
    		int h = origImage.Height;
    
    
    	
    		// Iniziamo il lavoro con la classe wbresize...
    
    		wbResize ImageResizer = new wbResize();
    		ImageResizer.LoadImage(Server.MapPath(imgName));	//accetta path, image e stream
    		ImageResizer.SetFileType(ThumbType);			//Tipo di output [jpg, gif, bmp, tiff, png]
    	
    	
    	
    	
    	
    	
    
    		// ridimensionamento FORZATO alle dimensioni indicate (resize_w, resize_h). Proporzioni non mantenute.
    		if (func=="a")
    		{
    		
    			ImageResizer.SetThumbSize(resize_w, resize_h, true, true);		// Width, Height, forzatura si/no, superforzatura
    		
    		}
    		// ridimensionamento alle dimensioni indicate (resize_w, resize_h), anche se l'immagine è più piccola. Proporzioni mantenute.
    		else if (func=="g")
    		{
    			
    			ImageResizer.SetThumbSize(resize_w, resize_h, false, true);		//Width, Height e forzatura
    		
    		}
    		// ridimensionamento alle dimensioni indicate (resize_w, resize_h), ma solo se l'immagine è più grande. Proporzioni mantenute.
    		else if (func=="l")
    		{
    		
    			ImageResizer.SetThumbSize(resize_w, resize_h, false, false);		//Width, Height e forzatura
    		
    		}
    
    
    
    		// Alcuni parametri che possono essere qui variati in qualsiasi momento...
    		
    		ImageResizer.SetOptionHighQuality(true);				// Alta qualità
    		ImageResizer.SetOptionJpegQuality(80);					// Qualità JPEG
    		ImageResizer.SetOptionFilter(InterpolationMode.HighQualityBicubic); 	// Filtro di Interpolazione
    	
    		print(ImageResizer.Resize(),ThumbType);
    }
    
    
    
    
    
    
    
    
    
    private void print(MemoryStream memorystream, string filetype)
    
    {
    	//stampa nell'outputstream un'immagine (passata in un memorystream)
    	
    	switch (filetype)
    	{
    		default: Response.ContentType = "image/jpeg"; break;
    	}
    	
    	memorystream.WriteTo( Response.OutputStream );
    	
    }
    
    </script>
    Where there is a will, there is a way

  6. #6
    codice (scremato del non essenziale) della pagina wbresize.cs:
    codice:
    
    
    public class wbResize
        {
    
            public int thumbWidth = 0;
            public int thumbHeight = 0;
            private string FileType = "jpg"; //jpg,gif,bmp,tiff,png
    
            private System.Drawing.Image rImage = null;
            private int originalWidth = 0;
            private int originalHeight = 0;
            int JpegQuality = 100;  //0-100
            bool TiffCompress = true;
            bool HighQuality = true;
            InterpolationMode Filter = InterpolationMode.Low;
            byte GifPalette = 255;  //9-255
            byte GifDepth = 8;      //0,255,1,2,4,8
            long ByteSize;
    
            /****************************************************************************************/
            /****************************************************************************************/
    
            public void LoadImage(string path)
            {
                if (!File.Exists(path)) { throw new FileNotFoundException(); }
                try { LoadImage(System.Drawing.Image.FromFile(path)); }
                catch { throw new FileNotFoundException(); }
            }
            public void LoadImage(Stream stream)
            {
                try { LoadImage(System.Drawing.Image.FromStream(stream)); }
                catch { throw new FileNotFoundException(); }
            }
            public void LoadImage(System.Drawing.Image image)
            {
                rImage = new Bitmap(image);
                originalWidth = image.Width;
                originalHeight = image.Height;
    			image.Dispose();
    			image = null;
            }
            public void UnloadImage()
            {
                if (rImage!=null) rImage.Dispose();
                rImage = null;
            }
    
            /****************************************************************************************/
            /****************************************************************************************/
    
    
    
            private double scaleProportional(double originalA, double originalB, double requestedA)
            {
                //scala una delle due dimensioni eseguendo una proporzione
                return Math.Ceiling(requestedA * originalB / originalA);
            }
    
    
    
    
    
    
            public void SetThumbSize(double requestedWidth, double requestedHeight, bool forceDimension, bool allowSuperSize)
            {
            SetThumbSize(requestedWidth, requestedHeight, 0, forceDimension, allowSuperSize);
            }
            
            
            
            
            
    
            
            // ED ECCOCI ALLA FUNZIONE DI RIDIMENSIONAMENTO PRINCIPALE...
            //
            public void SetThumbSize(double requestedWidth, double requestedHeight, int scaleFactor, bool forceDimension, bool allowSuperSize)
            {
                //calcola la dimensione dell'immagine ridotta
                //[restituisce 0,0 in caso di parametri insufficienti]
    
                int thumbwidth = 0, thumbheight = 0;
    
                bool executeResize = true;
    
                if (!allowSuperSize && scaleFactor > 100) scaleFactor = 100;
                if (scaleFactor < 0) scaleFactor = 0;
    
                //se una dimensione è più grande dell'immagine e l'altra no, 
                //la diminuisce fino a renderla pari all'immagine
                if (!(!forceDimension && requestedHeight != 0 && requestedWidth != 0) && !allowSuperSize)
                {
                    if (originalWidth > requestedWidth && originalHeight < requestedHeight) requestedHeight = originalHeight;
                    if (originalWidth < requestedWidth && originalHeight > requestedHeight) requestedWidth = originalWidth;
                    executeResize = (originalWidth >= requestedWidth && originalHeight >= requestedHeight && scaleFactor >= 0 && scaleFactor < 100);
                }
    
                if (executeResize)
                {
                    //l'immagine è da ridimensionare: calcola le dimensioni della miniatura
                    if (scaleFactor == 0)
                    {
                        if (requestedWidth == 0 && requestedHeight != 0)
                        {
                            // forzata requestedHeight
                            thumbwidth = Convert.ToInt32(scaleProportional(originalHeight, requestedHeight, originalWidth));
                            thumbheight = Convert.ToInt32(requestedHeight);
                        }
                        else if (requestedHeight == 0 && requestedWidth != 0)
                        {
                            // forzata requestedWidth
                            thumbwidth = Convert.ToInt32(requestedWidth);
                            thumbheight = Convert.ToInt32(scaleProportional(originalWidth, requestedWidth, originalHeight));
                        }
                        else if (requestedHeight != 0 && requestedWidth != 0)
                        {
                            if (forceDimension)
                            {
                                // forzata sia requestedWidth che requestedHeight
                                thumbwidth = Convert.ToInt32(requestedWidth);
                                thumbheight = Convert.ToInt32(requestedHeight);
                            }
                            else
                            {
                                double newWidth, newHeight;
                                // scala le dimensioni in proporzione per mantenerle
                                //nel riquadro requestedWidth/requestedHeight
                                newHeight = requestedHeight;
                                newWidth = scaleProportional(originalHeight, newHeight, originalWidth);
                                if (newWidth > requestedWidth)
                                {
                                    newHeight = Convert.ToInt32(scaleProportional(newWidth, requestedWidth, newHeight));
                                    newWidth = Convert.ToInt32(requestedWidth);
                                }
                                thumbheight = Convert.ToInt32(newHeight);
                                thumbwidth = Convert.ToInt32(newWidth);
                                if (thumbwidth > originalWidth && thumbheight > originalHeight && !allowSuperSize)
                                {
                                    thumbheight = originalHeight;
                                    thumbwidth = originalWidth;
                                }
                            }
                        }
                        else //requestedHeight == 0 && requestedWidth == 0
                        {
                            thumbwidth = 0;
                            thumbheight = 0;
                        }
                    }
                    else
                    {
                        // scalata: percentuale delle dimensioni
                        thumbwidth = (originalWidth * scaleFactor / 100);
                        thumbheight = (originalHeight * scaleFactor / 100);
                    }
                }
                else
                {
                    // sovradimensionamento (si impostano le nuove dimensioni a 0 per evitare il ridimensionamento)
                    thumbwidth = originalWidth;
                    thumbheight = originalHeight;
                }
                thumbWidth = thumbwidth;
                thumbHeight = thumbheight;
            }
    
            /****************************************************************************************/
            /****************************************************************************************/
    
            public string Report() { return Report(""); }
            public string Report(string key)
            {
                string output = "";
                string depth = "";
                switch (key.ToLower())
                {
                    case "width": output = thumbWidth.ToString(); break;
                    case "height": output = thumbHeight.ToString(); break;
                    case "filetype": output = FileType; break;
                    case "jpegquality": output = JpegQuality.ToString(); break;
                    case "filter": output = Filter.ToString(); break;
                    case "size": output = Convert.ToString(Math.Round((double)ByteSize / 1024,2)) + " Kb"; break;
                    default:
                        output = output + FileType + " Image - " + thumbWidth.ToString() + "x" + thumbHeight.ToString();
                        switch (FileType)
                        {
                            case "jpg": output = output + " - Quality " + JpegQuality.ToString() + "%"; break;
                        }
                        output = output + " - Filter " + Filter.ToString();
                        output = output + " - Size " + Convert.ToString(Math.Round((double)ByteSize / 1024,2)) + " Kb";
                        break;
                }
                return output;
            }
    
            /****************************************************************************************/
            /****************************************************************************************/
    
    
    
    
            public void SetFileType(string filetype)
            {
                FileType = filetype.ToLower();
            }
    
    
    
            public void SetOptionJpegQuality(int jpegquality)
            {
                JpegQuality = jpegquality;
                if (JpegQuality > 100) JpegQuality = 100;
                if (JpegQuality < 0) JpegQuality = 0;
            }
    
    
    
    
            public void SetOptionHighQuality(bool highquality)
            {
                HighQuality = highquality;
            }
    
    
    
    
            public void SetOptionFilter(InterpolationMode filter)
            {
                Filter = filter;
            }
    
    
    
            /****************************************************************************************/
            /****************************************************************************************/
    
    
    
    
    
    
            public MemoryStream Resize()
            {
     
     
     	    //salva su memorystream un'immagine ridimensionandola
    
                if (rImage == null) throw new System.ApplicationException("Image not loaded!");
    
                MemoryStream memorystream = new MemoryStream();
                ByteSize = 0;
                
                try
                {
                    System.Drawing.Image thumbnail = new Bitmap(thumbWidth, thumbHeight);
                    System.Drawing.Graphics graphic = System.Drawing.Graphics.FromImage(thumbnail);
                    if (HighQuality)
                    {
                        graphic.InterpolationMode = Filter;
                        graphic.SmoothingMode = SmoothingMode.HighQuality;
                        graphic.PixelOffsetMode = PixelOffsetMode.HighQuality;
                        graphic.CompositingQuality = CompositingQuality.HighQuality;
                    }
                    else
                    {
                        graphic.InterpolationMode = InterpolationMode.Low;
                        graphic.SmoothingMode = SmoothingMode.HighSpeed;
                        graphic.PixelOffsetMode = PixelOffsetMode.HighSpeed;
                        graphic.CompositingQuality = CompositingQuality.HighSpeed;
                    }
                    graphic.DrawImage(rImage, 0, 0, thumbWidth, thumbHeight);
    
    
                    /* EVENTUALI OPERAZIONI SULL'IMMAGINE QUI... */
    
                    EncoderParameters encoderParameters;
                    encoderParameters = new EncoderParameters(1);
                    ImageCodecInfo[] info = ImageCodecInfo.GetImageEncoders();
    
                    switch (FileType)
                    {
    
                         default: 
                         encoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, JpegQuality);          
                         thumbnail.Save(memorystream, info[1], encoderParameters);
                         break;
                         
                    }
                    ByteSize = memorystream.Length;
                    graphic.Dispose();
                    graphic = null;
                    thumbnail.Dispose();
                    thumbnail = null;
                }
                catch
                {
                    throw new System.ApplicationException("Unable to resize the image");
                }
                return memorystream;
    
            }
        }
    Where there is a will, there is a way

  7. #7
    non c'è alcun errore, dove hai messo l'unloadimage() ?

    mi posti l'intera pagina di dove è presente?
    Non ho paura dei miei pensieri, ma ho paura ad esprimerli.
    La libertà d'espressione oggi, potrebbe diventare prigionia del corpo domani.

  8. #8
    prova a metterlo anche tu alla fine del primo o del secondo script:

    - se lo metti alla fine dello script .cs, vedrai che le miniature spariscono dalla pagina asp: frugando nell'errore ho scoperto che nella pagina .cs non viene riconosciuto l'oggetto ImageResizer per cui la miniatura neanche viene visualizzata.

    - se lo metti alla fine dello script .aspx ( dopo print(ImageResizer.Resize(),ThumbType); ) vedrai che le miniature compaiono si, ma se provi ad eliminare l'immagine originale con un semplice pulsante associato a uno script asp, non ci riuscirai : insomma sono punto e a capo...
    Where there is a will, there is a way

  9. #9
    putroppo io mi fermo qui, il c# l'utilizzo pochissimo ed in generale il framework .net mi stà antipatico, quindi non riesco a darti una soluzione valida, se non quella di provare a cambiare script con qualcosa di simile
    Non ho paura dei miei pensieri, ma ho paura ad esprimerli.
    La libertà d'espressione oggi, potrebbe diventare prigionia del corpo domani.

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.