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

    getThumbnailImage...eeeeeeeeh?

    Ciauz, espongo brevemente. Su un server uno script che gestisce immagini (getThumbnailImage, conoscete?) funziona perfettamente, su un altro no e restituisce come errore:

    The process cannot access the file "d:\sito.it\sito.it\temp\img.jpg" because it is being used by another process.

    sulla riga della cancellazione di un'immagine
    System.IO.File.Delete(Server.MapPath(strFileName)) ;

    nè crea l'immagine come da funzione...devo prendermela col l'hoster o sbaglio qlkosa e uno dei due server "non ci fa caso" ?
    ...Ignorance is bliss...

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    4,127
    nel 2^, prova ad aggiungere prima di cancellare:
    myImg.Dispose()
    dove myImg è l'oggetto di System.Drawing.Bitmap ke ha come contenuto l'img riportata nella variabile strFileName

  3. #3
    li ho messi già i Dispose , può essere un problema d server ke l'ASP.NET sia configurato in modo errato?

    cmq ti posto lo script
    codice:
    <%@ Page Language="C#" Debug="true"%>
    <%@ import Namespace="System.Drawing" %>
    <%@ import Namespace="System.Drawing.Imaging" %>
    <%@ import Namespace="System.Text.RegularExpressions" %>
    <%@ import Namespace="System.IO"%>
    <script runat="server">
    
        int MaxWidth; // Larghezza massima dopo il quale l'immagine viene ridimensionata
        int MaxHeight;  // Altezza massima dopo il quale l'immagine viene ridimensionata
        int MaxWidth_thumb;
        int MaxHeight_thumb; 
    	int ScaleFactor;
        System.Drawing.Image oldImage, newImage, newImage_thumb;
    
        void Page_Load(Object sender, EventArgs e) {
            if ( Request.QueryString["FileName"] != null ) {
    		string strFileName;
    		string in_dir_tekstudio;
    			if (Request.QueryString["id"] != null){
                	strFileName = Convert.ToString("temp/"+Request.QueryString["FileName"]);
    				    if (Request.QueryString["FileName"]=="immagine.jpg"){
    						MaxWidth = 400;
     						MaxHeight = 400;
    						MaxWidth_thumb = 190;		// X le img da copertina
       						MaxHeight_thumb = 250;
    					}else{
    						MaxWidth = 640;
     						MaxHeight = 480;
    						MaxWidth_thumb = 120;		// X le img x skede
       						MaxHeight_thumb = 120;
    					}
    			}
    			else{ 
    				strFileName = Convert.ToString("temp/immagine_biografia.jpg"); 
    					MaxWidth = 400;
     					MaxHeight = 400;
    					MaxWidth_thumb = 270;		// X la biografia
       					MaxHeight_thumb = 200;
    			}
                if ( strFileName != "" ) {
                    try {
                        oldImage = System.Drawing.Image.FromFile(Server.MapPath(strFileName));
                            // Immagine troppo grande, visualizzo la miniatura
    						if (oldImage.Width > MaxWidth){
                          		newImage = oldImage.GetThumbnailImage(MaxWidth, (oldImage.Height*MaxWidth/oldImage.Width), null, IntPtr.Zero);
    							newImage_thumb = oldImage.GetThumbnailImage(MaxWidth_thumb, (oldImage.Height*MaxWidth_thumb/oldImage.Width), null, IntPtr.Zero);
    						}else{ if (oldImage.Height > MaxHeight){
    									newImage = oldImage.GetThumbnailImage((oldImage.Width*MaxHeight/oldImage.Height), MaxHeight, null, IntPtr.Zero);
    									newImage_thumb = oldImage.GetThumbnailImage(MaxHeight_thumb, (oldImage.Width*MaxHeight_thumb/oldImage.Height), null, IntPtr.Zero);
    							 }else 
    							        newImage = oldImage.GetThumbnailImage(oldImage.Width, oldImage.Height, null, IntPtr.Zero);
    						}
                            newImage_thumb = oldImage.GetThumbnailImage(MaxWidth_thumb, (oldImage.Height*MaxWidth_thumb/oldImage.Width), null, IntPtr.Zero);
                            Response.ContentType = "image/jpeg";
                          	newImage.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
                            newImage_thumb.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
    						Environment.CurrentDirectory=AppDomain.CurrentDomain.BaseDirectory;
    					 	if (Request.QueryString["id"] != null){
    							newImage.Save("img/"+Request.QueryString["id"]+"/"+Request.QueryString["FileName"],System.Drawing.Imaging.ImageFormat.Jpeg);
    							newImage_thumb.Save("img/"+Request.QueryString["id"]+"/thumbs/"+Request.QueryString["FileName"],System.Drawing.Imaging.ImageFormat.Jpeg);
    
    						}else{
    							newImage.Save("img/immagine_biografia.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
    							newImage_thumb.Save("img/thumbs/immagine_biografia.jpg",System.Drawing.Imaging.ImageFormat.Jpeg);
    						}
                            oldImage.Dispose();
                          	newImage.Dispose();
    						newImage_thumb.Dispose();
    						newImage_thumb = null;
                            oldImage = null;
                          	newImage = null;
    						
    
                    } catch (Exception ex) {
                        Response.Write(ex.Message);
                    }
    						System.IO.File.Delete(Server.MapPath(strFileName));
    					
                }
            }
        }
    </script>
    ...Ignorance is bliss...

  4. #4
    Utente di HTML.it
    Registrato dal
    Sep 2002
    Messaggi
    4,127
    nn so xkè ma mi viene da togliere
    newImage_thumb = null;
    oldImage = null;
    newImage = null;
    prova senza

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.